Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Movement physics part II

This topic is 5595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, I have a ball rolling on the ground, and possibly bouncing off the ground as well. The ground can be of any angle. I have: 1: The direction and speed I want to move at(expressed as an acceleration vector) 2: The normal of the ground (expressed as a normalised vector) 3: The Current direction and Speed (as a vector) 4: The Friction of the surface (or the friction of the air) expressed as a 2d vector. 5: Gravity. Every frame I calculate the force acting on the ball, like this: 1: Force = IntendedAcceleration 2: Force = Force + GroundNormal 3: Force.y = Force.y + Gravity Then I do a whole bunch of calculations to make sure that applying friction doesn''t cause the ball to accelerate in the opposite direction. Each calc goes like this If Force.X > 0 //moving right If Force.x + Friction.x > 0 // can add the friction Force.X += Friction.x else // can''t add the friction, because it would result in negative movement... BAD! Force.X = 0 End if elseif Force.X < 0 //moving left // basically as above, but reversed ... ... // same as above for force.z Next I add the Force to the acceleration and then add the acceleration to the ball''s current speed. Lastly, I perform the same friction calculation on the ball''s speed (just incase the acceleration is 0, but the ball is still moving). Now, the result of all this works very nearly perfectly, for a rolling ball, even up and down slopes. I''m a little concerned about the friction calcs because they seem overly clumsy and if someone can suggest a better method I would be very happy. I tried NOT applying friction to the acceleration, but that just meant that the acceleration never degraded. Applying it both the acceleration and the speed seems wrong, and I am pretty sure that the fact that it looks OK is purely co-incidental because of the vector sizes I''m using. BUT, the real problem is that I would like to use the exact same calculations for rolling behaviour as for impact and bounce behaviour. I figure that I have to work out the angle that the ball impacts the terrain, as well as the angle of the plane that the terrain lies in in order to calculate the new angle of reflection (in 2d on a flat plane, it''s basically 180-degrees-angleofincidence). If you''re rolling on a 2d flat plane then your angleofincidence is 0 and your resultant angle is 180, so... I figure that by doing an angleofincidence + SomeKindOfFunkyThingWithTheAngleOfThePlane would give me a useful result that I can apply to the ball... BUT HOW! My brain seems to be hard-wired to work in sin/cos and angles, and I can work it all out on paper for a 2d collision, but this is in 3d and vector''s are faster so I really want to go that route. Just about all I know about the plane is its normal and its two composite triangles. And that''s about enough of that, i think. If anyone can help with the friction or the incidence calcs, I would be very happy indeed.

Share this post

Link to post
Share on other sites
I did something silimar with a sphere character. For friction I just multiplied the final velocity so 1.0 would be no friction, 0.98 would be a little bit and 0 would be infinite frition (it clearly would not move).

Here is how to bounce a ball. This is for a breakout/pong style game I did but you should be able to adpat it (courtest of Peter Hanely):

V -= 2*W*(V dot W)
V is ball velocity
W is wall unit normal

d = Vx*Wx + Vy*Wy
Vx -= 2* Wx*d
Vy -= 2* Wy*d

Hope it helps.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!