Skip to main content
gamedev.net
🔒 Locked

Projectile Physics

Started by DrEvil Apr 5, 2005 at 7:02 PM 3 replies 850+ views
Original Post
DrEvil
DrEvil
Have some questions about projectile physics. Suppose I have a grenade, with a known velocity and a maximum detonation time. I have a "thrower" position, and I have a target position, and finally a gravity constant. Can someone point me in the right direction for taking these "knowns" and coming up with an aim vector it would need to be thrown at to land near the target? ex: grenade velocity 600, max det time 4 seconds gravity 500 I have a feeling the solution isn't going to be easy. Some points in the right direction, or maybe even some ideas to fake it would be appreciated. It doesn't need to be exact. Thanks
bjle
bjle
EDIT: I think you can safely skip this post...

Basically you would split the problem up into two parts. (x and y)

For x, you find the acceleration (in your case 0), velocity (total velocity * cos(angle)), and finally position.

Then you do the same for y.

In the end you're going to end up with something you can't solve because there are an infinite number of vectors that will land around the right spot. What I would do, is loop through angles starting at 90 degrees straight up and then pointing more and more toward the target, until the time taken to hit the ground is less than the max det. time.

This is all off the top of my head (so I may have made a mistake) and it assumes some knowledge of calculus, so if you're still having trouble I'd be happy to explain further.

[Edited by - bjle on April 5, 2005 8:37:08 PM]
Arelius
Arelius
All Location, Velocity, and Accelerations are Vectors.

So, the location Lt of an object with velocity V , initial Location Li at time T is
Lt = Li + V*T

Adding in acceleration A (assuming constant)
Lt = Li + VT + (1/2)AT^2

Lt, Li, A are all constant

Lt - Li = VT + (1/2)AT^2

Now, given that you want it to land at the detonation time we know T

(t - Li - (1/2)AT^2)T = V

There is your vector, but that shows you the velocity vector you need to through the gernade at in order to get it there as it explodes (as from what I read, is what you want)... hmm, thinking of it, there must be something wrong with my math, however I post anyways in hopes that you can learn anything. I could show you how to do it with Calc, if you have taken that course though.
bjle
bjle
OOps, I think I made a mistake...for some reason I was half-way assuming we didn't know T. So I think you can ignore what I said earlier.

But Arelius, I think you meant (t - Li - (1/2)AT^2)/T = V?

Edit: Yep I just tested it an Arelius was completely right, (except for the typo).
DrEvil
DrEvil
I'm making an FPS bot, and am wanting to pre-calculate the aim vectors between each waypoint.

I had thought about just brute-force calculations.

for(i = 0 to numwaypoints)
for(j = 0 to numwaypoints)
for(angle = -90; angle < 90)
simulate the grenade with small timesteps using the games traceline, compare where the trace hits against the target position and give it a rating. pretty much only keep the results that end up landing closest the target.

I guess I would need to do this anyways to a certain degree to account for possible collisions and bouncing.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.