Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AndreTheGiant

gravity, and ball thrown up, falls down

This topic is 5557 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

If i have a ball that is thrown up in the air with an initial velocity vi, How do i model it so that it goes up, slows down, stops, and falls back to earth just as in real life? Ive taken a few physics courses so I know how this all works. I even know some of the formulas. But where i get tripped up, is when I try to put it in a computer program, its more complicated because instead of just calculating where the ball is once, you have to keep track of where it was, and find out where it is many many times per second in the update() function. Here are the 3 formulas that i think I might need: (final velocity) = (init velocity) + (acceleration)*(time) (distance) = (velocity) * (time) (distance) = (init velocity)*(time) + .5*(acceleration)*(time)*(time) also, I know that gravity acceleration is -9.8 m/sec/sec. I know that normally, I could just use the third formula to find out where the ball is at any time. But since the time that I have available to me in the update function is NOT the time since the ball was thrown up, but rather the time since the last update. Im sure this is probably one of the most popular questions asked in this forum but I couldnt find a suitable answer. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I would go with the distance formula that uses the acceleration value. You get a more accurate representation.

If your time is in milliseconds, don't forget to model your acceleration value that way ( I believe you would represent it as -9.8 / 1000^2). Otherwise, express your time in seconds (divide time by 1000.0f and leave acceleration at -9.8)

Give it a try, see how it looks.


[edited by - Waverider on April 2, 2003 5:06:22 PM]

Share this post


Link to post
Share on other sites
Thanks for the quick reply, Waverider.

quote:

I would go with the distance formula that uses the acceleration value. You get a more accurate representation.



when you said this, did you mean that if i didnt use this formula, that I would not get the accelerating affect of the ball? ie that the ball would fall faster and faster as time goes by? Or were you refering to something else?

Because I thought That I might be able to combine the other two formulas to achieve the same effect (of acceleration):

At the beginning of each update function, I would calculate the new velocity of the ball using my first formula, and then get the distance delta since the last update using my second formula. Would this not also model the acceleration?

The reason Im thinking about using the first two formulas instead of the third one is because, even though all 3 of the formulas have (time) in them, Im pretty sure the third formula uses time quite differently. The third formula would need the time since the ball was thrown into the air (I think), while the first two formulas only need the time since I last updated the position of the ball. Convieniently, the time since I last updated the ball is exactly what I pass into my update() function.


quote:

Give it a try, see how it looks.



yea, thats usually the easiest way to figure stuff out like this, but
1) I currently cant see how anything looks because nothing shows up on the screen at all! Im pretty sure this is due to a flaw in my physics logic, hence why Im asking this question.
2) Im not at home right now. Just thought I''d ask this now so it would be nice and answered when I got home

Thanks again!


Share this post


Link to post
Share on other sites
quote:
when you said this, did you mean that if i didnt use this formula, that I would not get the accelerating affect of the ball? ie that the ball would fall faster and faster as time goes by? Or were you refering to something else?

The ball would still accelerate and act like a ball, however it wouldn''t be as accurate a representation of a projectile if you were to use the third formula. What happens is that as time goes on and you use the timestep to generate the next position, the actual position of the ball begins to veer off the "true" path of the ball, and eventually the position could be completely off from where it should be. Timesteps have the unfortunatly side effect of not being able to look at the physics of the trajectory "as a whole" in a sense, because it works with discrete timesteps. Calculus, which works with limits as timesteps goes to 0, is much more accurate because the theory and stuff is based on limits and 0 widths. It''s seems automagically, but that''s how I think of it so it makes more sense to me

quote:
I know that normally, I could just use the third formula to find out where the ball is at any time. But since the time that I have available to me in the update function is NOT the time since the ball was thrown up, but rather the time since the last update.

You could keep a static variable inside the function that keeps track of the total time passed. Pass to the function the amount of time that has passed between updates, it adds it to the accumulator, and the total time is maintained. Set up a special condition so that if the function is passed a negative number for instance (don''t want to mess with 0 due to potential floating-point problems), it knows to reset the total time.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!