Sign in to follow this  
moose517

flying object physics

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this