How Rotate Enemy towards Player

How can i get the enemy to rotate towards the players position? I can rotate it along the x,y, z but how to i get the players location and turn the enemy towards them.

using UnityEngine;
using System.Collections;

public class RotateEnemyNmove : MonoBehaviour {

    public Transform target;
    public float turnSpeed = 5.0f;
    public float speed = 3.0f;
   
    public Vector3 _dir;
   
   
    void Start () {
        target = GameObject.FindWithTag("FPSController").transform;
    }
   
    void Update () {
        if(target){
            _dir = target.position - GetComponent<Rigidbody>().position;
            _dir.Normalize();
            Debug.Log (_dir);
        }
    }
   
    void FixedUpdate() {
        GetComponent<Rigidbody>().AddForce(_dir * speed);
        //transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), turnSpeed * Time.deltaTime);
        transform.rotation = Quaternion.Euler(0, 90, 0);
    }
}
1 Like
3 Likes

That defiantly worked Thanks!
However my enemys back is looking at me not his face.

Can i assign the front of my model some how? Or how do i get him flipped around?

transform.LookAt(target);

2 Likes