# Gravity for dummies

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

## Recommended Posts

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 !!

##### Share on other sites
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.

##### Share on other sites

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 ?

##### Share on other sites
The distance an object falls after t seconds is equal to -4.9t^2.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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 ...

:(

##### Share on other sites
Quote:
 Original post by JuksosahIf 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}

##### Share on other sites
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.

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015442
×