Jump to content
  • Advertisement
Sign in to follow this  
Juksosah

Gravity for dummies

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

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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 ?

Share this post


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


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


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


Link to post
Share on other sites
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
}



Share this post


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


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!