Hi guys,
I’m trying to get an enemy to move towards my player tagged player within the radius defined. However, no matter the number defined the enemy will only move if if(heading.sqrMagnitude >= radius * radius).
Below you can see the relevant code:
function Update () {
target = GameObject.FindWithTag("Player").transform;
var heading = target.position - myTransform.position;
var distance = heading.magnitude;
var direction = heading / distance;
heading.y = 0;
if(target.tag == "Player") {
if(heading.sqrMagnitude <= radius * radius){
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}