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

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

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

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 33
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631745
• Total Posts
3002004
×