I've got a problem with my script, I want the enemy of mine, follow and rotate towards the player. while he's moving around. It seem to work nice, but when my player turning rotating 180 on y, my enemy seems to go back a lot(his position), and only when my player returning to his normal rotation , the enemy seem to come back. What did I do wrong?
public class EnemyTesting : MonoBehaviour
{
public GameObject player;
public float speed = 1.5f;
public float turnRate;
private void Update()
{
Vector3 toTarget = player.transform.position - transform.position;
float angleToTarget = Vector3.Angle(transform.forward, toTarget);
Vector3 turnAxis = Vector3.Cross(transform.forward, toTarget);
transform.RotateAround(transform.position, turnAxis, Time.deltaTime * turnRate * angleToTarget);
transform.Translate(toTarget * speed * Time.deltaTime);
}