View Full Version : Projectile for a game
I'm writing a video game. For the AI i need to be able to calculate the proper initial velocity for a given angle to hit a target a certain x,y distance away. I don't want to use time in the formula. Does any one know a formula for doing this? I found something about a "gunnery law" that looked similar to what i needed, but i couldn't find the formula. Any help would be appreciated since i'm a programmer and not much of a physics person. Thanks.
Andrew Mason
Mar8-05, 06:13 PM
I'm writing a video game. For the AI i need to be able to calculate the proper initial velocity for a given angle to hit a target a certain x,y distance away. I don't want to use time in the formula. Does any one know a formula for doing this? I found something about a "gunnery law" that looked similar to what i needed, but i couldn't find the formula. Any help would be appreciated since i'm a programmer and not much of a physics person. Thanks.
If the target is at the same height as the launch, you can use:
y= vsin\theta t - \frac{1}{2}gt^2
where: t = \frac{x}{vcos\theta}
If x = R (range) and y = 0, you have:
vRtan\theta = \frac{gR^2}{v^2cos^2\theta}
v^3= \frac{gR}{tan\theta cos^2\theta}
v = \sqrt[3]{\frac{gR}{sin\theta cos\theta}}
AM
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.