Jump to content
  • Advertisement
Sign in to follow this  
moose517

flying object physics

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

i am working on a game for school. It is like tanks where you shoot at a target across the screen and blow the target up. The only problem is that the physics equations that i have tried dont work right. i wanted to see if anybody had equations that could be used to position the ball every step of the way across the screen. i have used some from my physics textbook but the ball moves like an inch and stops. it doesn't do anything after that.

Share this post


Link to post
Share on other sites
Advertisement
I'm afraid you'll need to be more specific. What "equation" are you using now, and how exactly are you implementing it in code?

Share this post


Link to post
Share on other sites
Assuming no air resistance, the problem is that of Newtonian motion with constant gravity. If the projectile is fired from (x0, y0) with velocity v0 at an angle θ from the horizontal, then the position of the particle at a later time t is given by:

x(t) = x0 + v0cos(&theta)t
y(t) = y0 + v0sin(&theta)t - gt2/2

In terms of a game-loop, this corresponds to performing the following operations once upon firing:

vx = v0cos(&theta)
vy = v0sin(&theta)

and these once per frame:

d := amount of time since previous frame
x = x + vx*d
vy = vy - g*d
y = y + vy*d - g*d*d/2

Admiral

Share this post


Link to post
Share on other sites
If I had to guess what was happening I'd say you aren't taking into consideration the fact that the time variable is continuously changing each frame. The equations in your physics book typically solve for a particle's position at a certain, known, time. In a game or simulation, typically only the time since the last frame is kept. So, you will start with a certain initial x and y position, an initial velocity, and an initial angle. Then, each frame you'll find the particle's new position using the delta time (time since the last frame), the particle's current position, and it's current velocity (which should be changing due to acceleration from gravity). TheAdmiral's post covers most of what you need to do.

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!