Trivial gravity question
Hi there, I''m sorry I have to post such a trivial question to you all - But I''ve lately got the interest of adding physics to my applications. But the bad thing is that I''ve not touched any physics in many many years and I''ve forgotten everyting about it..
So, what I want to do is to simulate the effect of gravity on a object I''ve got. I''ve made a vector class that can deal with adding up vectors and stuff like that.
As far as I know gravity on earth is 9.81 m/s^2, and if I''m right this would mean that the gravity is multiplied by itself every second it''s in freefall.. Anyhow, in my app the gravity multiplied itself by each frame I rendered and that was way too fast, so I figured I could make a timer, and it checks if the time is 1 second more than last time it calculated gravity; it''ll multiply.. But this made the accelleration very jumpy - I can''t get my head around this at the moment and I''m sorry for the english, it''s late at night and I''m out of ideas at the moment.. If there''s anybody that can enlighten my ignorance about this and even show me a little code example on how to do this properly I''d be very happy!
I didn''t take physics in a while either but ...
it''s not multiplied its added ie first sec- 10m/s second sec- 20m/s
quote:
mean that the gravity is multiplied by itself every second it''s in freefall
it''s not multiplied its added ie first sec- 10m/s second sec- 20m/s
I''ve always liked to look at acceleration units in seperate parts. Instead of m/s2, think of it in terms of (m/s) / s. I.e change in velocity per second.
Zipster''s right. All that figure means is that the objects velocity increases by 9.81 m/s every second. So each frame add an amount of velocity to the object based on how quickly the last frame was drawn (assuming non-constant frame rate, etc).
Peace,
Doc.
The following statement is true. The previous statement is false.
Peace,
Doc.

My stuff.Shameless promotion: FreePop: The GPL god-sim.
quote:
Original post by VBeir
I didn't take physics in a while either but ...
it's not multiplied its added ie first sec- 10m/s second sec- 20m/s
Well, doesn't that just wrap it up and really tell how ignorant I really am?

[edited by - kenwi on May 20, 2003 11:00:22 PM]
quote:
Original post by Doc
Zipster's right. All that figure means is that the objects velocity increases by 9.81 m/s every second. So each frame add an amount of velocity to the object based on how quickly the last frame was drawn (assuming non-constant frame rate, etc).
It is important to know that this technique is very common and it can also be very inaccurate when the velocity is used to compute distance.
The problem is that acceleration changes the velocity continuously, but you are changing the velocity periodically.
The equations often (and wrongly) used are:
vk = vk-1 + at
dk = dk-1 + vkt
The correct equations are:
vk = vk-1 + at
dk = dk-1 + vk-1t + 1/2at2
t is the time interval.
[edited by - Jambolo on May 24, 2003 2:42:58 AM]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
vk = vk-1 + at
dk = dk-1 + vk-1t + 1/2at²
is not that correct, the order is wrong
dk = dk-1 + vk-1t + 1/2at²
vk = vk-1 + at
would be correct, beause in the first timeinterval you don''t have a velocity.
I C++ it simply looks like
a = force/m
s += (a/2)*t^2 + v*t
v += a*t
s is the way and v the velocity and t the time interval
t should be calculated like
t = delay / 1000
so if the delay is the time in milliseconds passed since the last frame you got the right timeinterval, but becareful that at least one millisecond has passed.
dk = dk-1 + vk-1t + 1/2at²
is not that correct, the order is wrong
dk = dk-1 + vk-1t + 1/2at²
vk = vk-1 + at
would be correct, beause in the first timeinterval you don''t have a velocity.
I C++ it simply looks like
a = force/m
s += (a/2)*t^2 + v*t
v += a*t
s is the way and v the velocity and t the time interval
t should be calculated like
t = delay / 1000
so if the delay is the time in milliseconds passed since the last frame you got the right timeinterval, but becareful that at least one millisecond has passed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement