Hello, I am writing a C# script to make a farmer face a gameobject. However, I only want the farmer to pivot on the y axis. So far my script is:
using UnityEngine;
using System.Collections;
public class choose_mole : MonoBehaviour {
private static int recieverclosestsq;
public Transform target;
public Vector3 relativepos;
void Update ()
{
recieverclosestsq = molepos.closestsq;
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
}
I can’t find anything useful that locks the x and z rotations. Please send in a detailed explanation if you can. Thank you for the help!