Sign in to follow this  
TWild

Gravity

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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) )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this