# Gravity

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

## Recommended Posts

I have a falling object that has no other forces acting on it other than gravity. I can use the equation V = V0+a*t to find the velocity and then add that vector to my position vector to find get the new position, correct? Or do I use the formula s = v0*t+0.5*a*t*t to find the displacement and add that to the new position? I'm getting myself confused on such a simple subject. When I use the former method, I get what looks like the correct results, while the latter is pretty screwed up.

##### Share on other sites
the latter tells you the displacement from the start (time = 0) and not the displacement since the last second, either add the result of the latter to sarting position and the result of the former to the position at the last second.

hope that helps

##### Share on other sites
use the former. you're changing directions all the time typically. the former gives you time stepped evaluation. The latter is good in simulations only really for ballistic movement where you never apply external changes of direction.

-me

##### Share on other sites
That clears it up - thank you both.

##### Share on other sites
i guess technically the latter would work fine as long as you're using v0 and a0 to mean "vel and acc last frame" and not "vel and acc at beginning of move". I think i ended up concluding that you should calc like so to get the simulation correct:

Vnow = Vlast + a*t;
Snow = Slast + Vlast*t + 1/2*a*t*t;

where t = time since last frame

maybe what you're missing is the extra calc of Vnow? That'd throw the sucessive frame's numbers off.

-me

##### Share on other sites
1. v = v0 + at; s = s0 + vt;
2. v = v0 + at; s = s0 + v0t + ½at2
#2 is correct. #1 is an approximation of #2 (called Euler integration). #1 is only an approximation because during the period t, the velocity is not constant. Unless there is a good reason to use the approximation, you should use the correct formula. One problem with the approximation is that you will get different results for different frame rates (or time steps).

Typically, t is the time since the last frame, and s0 and v0 are the position and velocity computed in the last frame.

Edit: typo

[Edited by - JohnBolton on June 8, 2006 2:15:37 PM]

##### Share on other sites
Those equations seem correct, but can t be used as the time since the previous frame? dy = y0 + (1/2)g*(dt)^2. The displacement is based on the total time squared, thus the longer an object is falling, the faster it falls, since t^2 increases faster. If t is reset, wouldn't this represent an object that just starts its descent rather than continuing it? Perhaps the extra term in equation 2, the v0t, accounts for this.

##### Share on other sites
For a frame-rate independent solution, you can take advantage of the fact that gravitational accelleration is roughly constant in this situation. (Unless you have objects falling from several kilometers above the ground...)

If v0 is the old velocity, t is the time elapsed since the last update, and a is your accelleration due to gravity, then the change in position from the previous update is
(delta)p = t * (v0 + (a * t / 2) )

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633402
• Total Posts
3011670
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!