Jump to content


Photo

Rolling ball?


  • Please log in to reply
7 replies to this topic

#1 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 10 February 2012 - 01:15 PM

Well I am once again making a 2.5D game, and it will have a rolling ball in it instead. But the ball, wont roll. I dont know how to make it roll! Help would be appreciated. I have tried googling and reasearching it and tried fooling around with the d3d_transform_add_rotation_x,y, and z and i did set rotation and axis and things but the furthest i have gotten in terms of actually making something rotate was either the ball rotated(ONCE) and the view rotated with it so it looks the same no matter what, or the other objects are rotating(still only once, not consistently.) Basicly I want it like the game shown here: jonahgames.coolpage.biz/game.html but in 3d. I have the ball and the floor and the lighting and what not. I also set culling to false, because when its true the front of the platforms dissapear(the ones facing the player) And it looks odd.
  • 0

#2 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 10 February 2012 - 02:21 PM

Sigh! If you don't know the maths behind the matrix transformations, you're not ready for making 3D games! Sheesh!


Rule 1: the order you do the transformations matters! You gotta rotate the ball first, THEN translate it.
Rule 2: the origin matters! Make sure the center of the ball is in (0,0,0) (No matter where the ball is in the room! Translate the rotated ball with (x,y,z) to get it to the right position, but draw it at (0,0,0)!), or else the ball won't look like it's rolling properly.
  • 0

#3 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 10 February 2012 - 10:14 PM

Well, I came here to try to understand the maths depending on what you mean. And how do I set the origin exactly? Some helpful pointers would be nice. Keep in mind I am looking for an answer that could HELP me, not tell me what I'm doing wrong and then not even telling me how to fix it. Thanks!
  • 0

#4 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 10 February 2012 - 11:10 PM

Hey!
Assuming the ball doesn't roll at a constant speed, you'll need to use its speed to create the angle it is to be drawn. If you're using hspeed and vspeed (or speed and direction), this will simply be the "speed" variable. Next you'll need to transform it so that the ball rolls at the logical angular speed according to its radius. Now we'll have use of the definition of radians:
radian=arc/radius
Or, in a more relevant format:
rotspd=speed/radius
Notice that this gives us the rotation speed, not the actual rotation. To add it to the current rotation you just need to store a variable that keeps track of the current rotation. So far:
//create event
rot=0
rotspd=0

//step event
rotspd=speed/radius
rot+=rotspd
And to answer your actual question: assuming the gameplay takes place in the xy-plane, you'll need to use d3d_transform_add_rotation_z:
d3d_transform_set_scaling(radius,radius,radius) //Set the translation to the scaling (_set_ removes all previous transformations)
d3d_transform_add_rotation_z(radtodeg(rot)) //rot is in radians, but the function takes degrees
d3d_transform_add_translation(x,y,z) //Add the translation after rotation
d3d_draw_ellipsoid(-1,-1,-1,1,1,1,texture,1,1,20) //Draw an ellipsoid with radius 1 at (0,0,0)
d3d_transform_set_identity()

Edited by TheSnidr, 10 February 2012 - 11:11 PM.

  • 0

#5 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 10 February 2012 - 11:18 PM

Now I am confused. Do I put the rotation code in the keyboard event? Or the draw event?
EDIT: Radius is not a defined variable... Maybe I should just give up.
DOUBLE EDIT: Okay, I have gotten it to work now. The only problem is that I probably dont have the origin set correctly so the object rolls on the anchor point of the corner of the object instead of the middle, how would I go about setting the origin exactly? And another problem, when I go left it still rotates right. But other then that its working like a charm so far!

Edited by howabout, 10 February 2012 - 11:27 PM.

  • 0

#6 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 10 February 2012 - 11:26 PM

Oh sorry, thought I explained it throughly. How much about game maker's 3D do you know?

The part where it draws the ellipsoid goes in draw event

Edited by TheSnidr, 10 February 2012 - 11:27 PM.

  • 0

#7 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 13 February 2012 - 08:48 AM

How much about game maker's 3D do you know?

Didn't his first post convey that? He's completely new to it.
  • 0

#8 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 15 February 2012 - 01:36 PM

How much about game maker's 3D do you know?

Didn't his first post convey that? He's completely new to it.

not completely new -_-
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users