# Calculating a projectiles angle required to hit object.

 0 I'm trying to use the formula from http://en.wikipedia.org/wiki/Trajectory_of_a_projectile to work out the angle required to launch a projectile a known distance with the launch height not being the same as the targets. I'm not sure if I've coded it right because the result seems to be incorrect. Any help is appreciated. ``````var distance : float; //target distance var height : float // launch height var reqAngle : float; function Start() { RequiredAngle(distance, height); } function RequiredAngle(x,y) { reqAngle = Mathf.Atan(Mathf.Pow(velocity,2) +Mathf.Sqrt((Mathf.Pow(velocity,4) -(gravity*(Mathf.Pow(gravity*x,2) +Mathf.Pow(2*y*velocity,2) /gravity*x))))); } `````` more ▼ asked Jan 30 '11 at 08:51 AM efreet 47 ● 5 ● 5 ● 7 Kindly look into this one for more reference :http://answers.unity3d.com/questions/49195/trajectory-of-a-projectile-formula-does-anyone-kno.html Dec 02 '11 at 02:48 AM Karsnen add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 For more reference Check this link below :http://answers.unity3d.com/questions/49195/trajectory-of-a-projectile-formula-does-anyone-kno.html more ▼ answered Dec 02 '11 at 03:27 AM Karsnen 736 ● 26 ● 45 ● 53 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 The inner-most bracket expression says to take g and multiply it by x-squared and then add two times y times v-squared. In your code you are squaring gravity times x and two times y times v. more ▼ answered Jan 30 '11 at 01:13 PM Graham Dunnett ♦♦ 11.7k ● 11 ● 20 ● 64 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1865
x286
x251
x11

asked: Jan 30 '11 at 08:51 AM

Seen: 2076 times

Last Updated: Dec 02 '11 at 03:27 AM