As the title says, I am making a top down style game, and am having difficulty getting enemies to rotate to face the player properly. I found this code from another post, and have tried tweaking the values of Vector3.RotateTowards, but I can’t quite get the result I’m looking for.
public Transform target;
public float speed;
void Update() {
Vector3 targetDir = target.position transform.position;
float step = speed * Time.deltaTime;
float moveStep = moveSpeed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
transform.rotation = Quaternion.LookRotation(newDir);
With this code, the enemy will rotate on all 3 axes, but will eventually become ‘invisible’. How do I isolate just the ‘z’ axis?
Thanks!
edit: I know this question has been brought up before, but I’ve looked through all the solutions I’ve found and haven’t been able to find one that suits my needs.