hey guys, i’m using this script to rotate my turret toward a target, it looks at my target only on z axis .is there any way to limit its rotation to be only rotated from 90 degrees to -90 degrees.
thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookOnlyOnZ : MonoBehaviour {
// Use this for initialization
public Transform target;
public float damping;
void Start () {
}
// Update is called once per frame
void Update ()
{
var lookPos = target.position - transform.position;
lookPos.z= 0;
var rotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
}