I currently have a turret model in my game, which, through the use of my custom script, rotates to look at the player. However, the script causes the turret to rotate on all axis, when I actually do not want it to look up or down.
Here is the script:
public GameObject player;
public bool friendly;
public float rotationSpeed;private Transform target;
private Quaternion lookRotation;
private Vector3 direction;void Start () {
}void Update () {
if (!friendly) {
target = player.transform;direction = (target.position - transform.position).normalized; lookRotation = Quaternion.LookRotation(direction); transform.rotation = Quaternion.Slerp (transform.rotation, lookRotation, Time.deltaTime * rotationSpeed); }
}
So, as you can see, it is written in C#. It simply rotates the turret to look at the player. However, it rotates the turret on the X, Y, and Z axis, when I do not want it to rotate on the Y axis.
Any suggestions or help?
Thanks.