Skip to main content
gamedev.net
🔒 Locked

Gravity

Started by TWild Jun 7, 2006 at 12:12 PM 6 replies 1k views
Original Post
TWild
TWild
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.
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
JasonL220
JasonL220
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
Palidine
Palidine
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
TWild
TWild
That clears it up - thank you both.
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
Palidine
Palidine
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
JohnBolton
JohnBolton
  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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
deej21
deej21
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.
Anthony Serrano
Anthony Serrano
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) )

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.