Archived

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

zip7000

a ball in a football game

Recommended Posts

hello, I would like to make a 2D speedball game like.(kind of football game). I am trying to find out an equation for the movement of the ball. So far, I didn''t find this equation. The equation has to consider the time, the acceleration.... Thank you for any help you can give! zip7000

Share this post


Link to post
Share on other sites
Say the ball accelerates at "acc" m/s^2, and the velocity vector is "vel", the position vector is "pos", the time from the previous frame to the current "t", and the angle the ball is moving in "a":

For each frame:

  
vel += acc * t * (cos(a), sin(a)) // m/s^2 * s = m/s

//(cos(a), sin(a)) is the vector reprecenting the direction of the ball

pos += vel * t // m/s * s = m



(If you´ve got a basic understanding of vectors and simple physics, it´s pretty easy...)

However, this "formula" assumes that the ball is in constant acceleration... If not, then just put and if-block before the first calc... The one that increases the velocity

Share this post


Link to post
Share on other sites
quote:
Original post by Tjoppen
However, this "formula" assumes that the ball is in constant acceleration...

I don''t think that''s a problem, since you used += rather than =. If the acceleration decreases, the change in the velocity decreases but the velocity still increases. If the acceleration is zero, the velocity remains constant (which is logical and proper), and if deceleration occurs, the velocity decreases. Sound.

The only difficulty this presents is for the game to accurately model all accelerations - gravity must be balanced by surface reaction, or your ball will eventually dig its way underground (and be lost to posterity)!

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
Using a vector for the balls velocity, and a vector for gravity, the balls new velocity is merely lastvelocity+gravity. The gravity vector will need to be scaled to match the time period.

All you will need to plug in is the original velocity, and this will give it the nice smooth arc it needs (As a plus, when the downwards velocity equals the original upwards velocity, the ball has reached the horizontal plane again. As the forward velocity shouldn''t change, it''s just a matter of the velocity vectors magnitude being >= it''s original magnitude.) For each frame, update the balls position simple by adding the vector x-y-z to it''s orgin''s x-y-z.

You''ll need some way to tell how much time has passed between the last frame and this one to scale the gravity vector properly. It might be wise to update the vectors less frequently and use interpolation for the position of the ball inbetween the gravity calculations (Gives the curve ''corners'', but it shouldn''t be noticable.)

Share this post


Link to post
Share on other sites