Before I was having problems with writing a script that would follow an object by rotating towards it on one axis… like a plane. I got something figured out, it works flawlessly except that it can’t turn all the way around it seems like 180 is the limit and it can’t follow targets behind itself. Any way I can fix this. Here’s my code:
#pragma strict
var target : GameObject;
var startRot : Quaternion;
var rotSpeed : float;
function Start () {
startRot = transform.rotation;
}
function Update () {
if(target != null){
var rotation = Quaternion.LookRotation(transform.position - target.transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, rotation, rotSpeed * Time.deltaTime);
var eulerAngles = transform.rotation.eulerAngles;
eulerAngles.y = startRot.eulerAngles.y;
eulerAngles.z = startRot.eulerAngles.z;
// Set the altered rotation back
transform.rotation = Quaternion.Euler(eulerAngles);
}