Hello, I have a script which is attached to enemy in order to make them to follow player.This is working fine only for sphere but not for cube.I mean sphere is following player but not cube. Cube is just coming to player’s position and then not moving at all.Can somebody tell where I went wrong.
Thanks.
This is script:
public GameObject prefab;
public GameObject target;
public float moveSpeed;
public float rotationSpeed;
void Start() {
}
void Update () {
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, moveSpeed * Time.deltaTime);
Vector3 vectorToTarget = target.transform.position - transform.position;
float angle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
Quaternion qt = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.RotateTowards(transform.rotation, qt, Time.deltaTime * rotationSpeed);
}