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)))));
}