so I want to make a tank, the head of the tank should follow the rotation of the camera in a slow pace.
this is what i have
{
public Transform box; // the camera
private Vector3 boxrot; //the rotation of the camera
private Vector3 head; // rotation of the head
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
boxrot = new Vector3(box.rotation.eulerAngles.x, box.rotation.eulerAngles.y, box.rotation.eulerAngles.z);
head = this.transform.eulerAngles;
if (head.y > boxrot.y) { head.y -= 1f; };
if (head.y < boxrot.y) { head.y += 1f; };
this.transform.rotation = Quaternion.Euler(270,0,head.y);
}
}
it works fine but at the front of the tank the rotation degreeās switch from 0 to 360. so the head moves back becouse 0 < 360
the head(green) wil go the long way to the camera(blue)