I need some help with a script I have right now its point and click but I want to limit how far up it can look or the X axis rotation. I do not want my guns to turn inwards towards the players ship when targeting something below or behind the spacecraft…
var turretRotationSpeed = 0.0;
var turret : Transform;
var shootAngleDistance = 0.0;
function Update ()
{
//Is the object mine on the network? if so then continue
if(networkView.isMine)
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit = new RaycastHit ();
if (Physics.Raycast (ray, hit))
{
//If the target is not there return or break till its not null
if(hit == null)
return;
if(Physics.Raycast (ray, hit))
{
var targetPoint = hit.collider.gameObject.transform.position;
var targetRotation = Quaternion.LookRotation ( targetPoint - turret.transform.position , Vector3.up);
turret.transform.rotation = Quaternion.Slerp(turret.transform.rotation, targetRotation, Time.deltaTime * turretRotationSpeed);
// If we are almost rotated towards target and player presses left mouse fire
var forward = turret.transform.TransformDirection(Vector3.forward);
var targetDir = hit.transform.position - turret.transform.position;
if (Input.GetMouseButton(0))
{
//If the turrents front "Z" is within a certain shooting angle and closest target
//tag is waypoint send message to firing script to "FIRE"
if (Vector3.Angle(forward, targetDir) < shootAngleDistance)
SendMessage("Fire");
}
}
}
}
}