Advertisement

a ball in a football game

Started by March 18, 2002 06:52 AM
3 comments, last by zip7000 22 years, 11 months ago
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
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 ballpos += 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
delete this;
Advertisement
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!
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.)
I am going to start this aspect of the program with these advices.

thank you everybody!!!

This topic is closed to new replies.

Advertisement