Currently I have a script to allow my ‘monster’ to target the player, but currently I’m having trouble making sure my monster can only rotate around the Y axis. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterAI : MonoBehaviour {
public Transform target;
public Transform myTransform;
public int MoveSpeed = 1;
public int rotationSpeed = 3;
// Use this for initialization
void Start () {
CharacterController controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
//transform.LookAt (Player);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * MoveSpeed * Time.deltaTime;
}
}
Essentially I don’t want my monster to rotate when the player jumps into an awkward angle. Any help would be appreciated.