#### Archived

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

# a ball in a football game

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

## 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 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 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 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 on other sites
I am going to start this aspect of the program with these advices.

thank you everybody!!!

• 16
• 11
• 11
• 9
• 49
• ### Forum Statistics

• Total Topics
631394
• Total Posts
2999749
×

## Important Information

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

Sign me up!