Calculate and apply trajectory formula to AI enemy weapon

My enemy ships have cannons that rotate up and down around their x axis, with the barrels pointing down the z axis.

I am trying to use the typical Slerp statement that you would use to smoothly rotate an object from the current rotation to the target rotation. I usually use Slerp to rotate around the Y axis, but am trying to alter it to use the x axis. I'm trying to calculate the target rotation by using a formula to find the required angle to reach the distance of a target:

alt text

Here is my code:

var distance = Vector3.Distance(transform.position, target.position);

var reqAngle = .5*Mathf.Asin((gravityV*distance)/(bulletSpeed*bulletSpeed));

turretOne.transform.rotation = Quaternion.Slerp (turretOne.transform.rotation, Quaternion.LookRotation(targetDirection), TurretRotationSpeed * Time.deltaTime);
turretOne.transform.eulerAngles = Vector3(0, turretOne.transform.eulerAngles.y, 0);

cannonOne.transform.rotation = Quaternion.Slerp (cannonOne.transform.rotation,  Quaternion.LookRotation(Vector3(reqAngle,targetDirection.y,0)), TurretRotationSpeed * Time.deltaTime);
cannonOne.transform.eulerAngles = Vector3(cannonOne.transform.eulerAngles.x, targetDirection.y, 0);

The Cannons are attached to the turret. The turrets can target the player character just fine, I left that code out. But I can get the cannons to adjust to the proper angle to shoot their projectiles the correct distance.

Thanks!

I finally got it. Incase anyone want to do the same thing here is the code I used. I didn't get the Slerp working, but am not to concerned about it right now.

var bulletSpeed = 55.0;
var gravityV = -9.5;
var reqAngle = .5*Mathf.Asin((gravityV*distance)/(bulletSpeed*bulletSpeed));
reqAngle = .75*(reqAngle*100);

turretOne.transform.rotation = Quaternion.Slerp (turretOne.transform.rotation, Quaternion.LookRotation(targetDirection), TurretRotationSpeed * Time.deltaTime);
turretOne.transform.eulerAngles = Vector3(0, turretOne.transform.eulerAngles.y, 0);

cannonOne.transform.eulerAngles = Vector3(reqAngle, turretOne.transform.eulerAngles.y, turretOne.transform.eulerAngles.z);

I had to cut the orriginal result of the angle buy 3/4 because of the enemy model setup. That's why I multiplied by .75. The cannons are attached to the turrets, that's why I included part of the turret code into the code.

The reason this doesnt work, is because the result is in radians rather than degrees.

reqAngle * 180 / Pi