How To Find Launch Angle for a rocket ?

Hello,

I am looking for a way to simulate rocket launch,
The rocket has fixed velocity, distance to the target is calculated.

How can i calculate the Angle needed for the shoot ?

I did try to work out the formula i find at wikipedia,
https://en.wikipedia.org/wiki/Trajectory_of_a_projectile
but i cant get the right results:

Angle required to hit coordinate x,y

1269258--56349--$angleFormula.png

var aAngle = Mathf.Atan( (v*v) + Mathf.Sqrt((v*v*v*v) - (g * ( g * (x*x) + 2 * h * (v*v)))) / g*x );
aAngle = aAngle * Mathf.Rad2Deg / 2;
print ("Angle => " + aAngle);

And This Part
→ Angle of reach

1269258--56350--$angleOfReach.png

	var newAngle = Mathf.Asin( x * g  / (v*v) ) * 0.5;
	print("newAngle => " + newAngle);

Any one know what am i doing wrong,
or have the currect way to achive the Angle for the launch ?

Thank you

I’m not sure what you’re doing wrong because you didn’t say what went wrong. Did try to use that formula with a rigid body and it failed to hit the target for example? Or are you getting compilation error? Or runtime errors?

Yes, the code compile Just fine,
However, when i try to calculate the angle needed by the launcher to hit the target the results are wrong.

Eg: I have distance to the target = x = 490.0 , the velocity of the projectile = 690metter/sec , gravity = ( Physics.gravity.magnitude ) = 9.8

Print results for the first code is 45 and is ok, but if i change the x value the results is the same.