Gravity for dummies
Need help ! (sorry my post is brief but im on a rush )
I just want to create a free falling body. Example : a bowling ball dropped from the top of the empire state building.
acceleration is -9.8m/s2
at each frame, I calculate velocity :
velocity += velocity - 9.8 * elapsedTime;
to get the position of the ball what should I do ??
position = velocity ...?
And if I drop an elephant instead of a bowling ball, it will fall at the same speed ?
What is the relationship with mass ?
thank you !!
A bowling ball does fall at the same speed as an elephant when you disregard air friction. Mass doesn't matter when dealing with a free-falling object, as it cancels out in the equations.
You can get the position like this:
position += velocity * elapsedTime;
Also, I think that your velocity equation should just be:
velocity += -9.8 * elapsedTime;
Otherwise you double your velocity every time before subtracting the acceleration.
You can get the position like this:
position += velocity * elapsedTime;
Also, I think that your velocity equation should just be:
velocity += -9.8 * elapsedTime;
Otherwise you double your velocity every time before subtracting the acceleration.
Thanks for your reply.
You're right for the velocity equation, it's a typo in my original post.
I tested the equation and my object was falling at a constant speed. There must be something wrong here.
Any ideas ?
You're right for the velocity equation, it's a typo in my original post.
I tested the equation and my object was falling at a constant speed. There must be something wrong here.
Any ideas ?
how are you doing your rendering? what are these units in? you probably want to scale the velocity by a "unit" variable that represents 1 meter in your game
Edit your code so that the velocity is constant, to make sure that your code is executing at a uniform rate. Then, if your object is falling at a constant speed, re-check your code for typos; those equations look right to me.
Okay I reviewed my code and was taking the elapsed time between 2 frames in milliseconds. Oops.
Now it falls, but it's fast !! maybe too fast.
I experimented a little and found that after 0.4 seconds, the object falls for 100 units.
I call them units because I haven't converted them in meters in my games. Suppose that 10 units is 1 meter.
If I want to be realistic to earth gravity, the object should fall 9.8 meters (approx 100 units ) for 1 second. (correct me if i'm wrong)
I will need to scale the velocity as funkymunky said, by 0.4 to keep this realist. Are you doing it this way ? All my subsequent physics calculations will have to be "scaled" this way ? Rather annoying, and i hate physics too ...
:(
Now it falls, but it's fast !! maybe too fast.
I experimented a little and found that after 0.4 seconds, the object falls for 100 units.
I call them units because I haven't converted them in meters in my games. Suppose that 10 units is 1 meter.
If I want to be realistic to earth gravity, the object should fall 9.8 meters (approx 100 units ) for 1 second. (correct me if i'm wrong)
I will need to scale the velocity as funkymunky said, by 0.4 to keep this realist. Are you doing it this way ? All my subsequent physics calculations will have to be "scaled" this way ? Rather annoying, and i hate physics too ...
:(
Quote:Original post by Juksosah
If I want to be realistic to earth gravity, the object should fall 9.8 meters (approx 100 units ) for 1 second. (correct me if i'm wrong)
No.
After an object has been falling for 1 second, it should have a velocity of 9.8 meters/second, and it will have fallen 4.9 meters.
After an object has been falling for 2 seconds, it should have a velocity of 19.6 meters/second, and it will have fallen 19.2 meters.
After an object has been falling for 3 seconds, it should have a velocity of 29.4 meters/second, and it will have fallen 43.2 meters.
void Update( float elapsedTimeInSecondsSinceLastUpdate ){ float delta = elapsedTimeInSecondsSinceLastUpdate; acceleration += -9.8 * delta;//assume these are all in meters velocity += acceleration * delta; position += velocity * delta; float positionInMeters = position * 0.1f; //10 units in a meter}
in conventional math, there is a position function
The psuedo-code takes variables of time, initial velocity, and initial position.
Position(time, init_velocity, init_position) = -4.9*(time)^2 + (init_velocity)*(time)+ (init_position)
as already stated, the mass makes no difference, only the air resistance, which for now I assume is negligible.
The psuedo-code takes variables of time, initial velocity, and initial position.
Position(time, init_velocity, init_position) = -4.9*(time)^2 + (init_velocity)*(time)+ (init_position)
as already stated, the mass makes no difference, only the air resistance, which for now I assume is negligible.
Have a look on my website, I have a bunch of video tutorials there that show how to implement gravity for a cannon ball in projectile motion.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement