I two different forms of movement for my player, one for dodging and one for normal walking. Dodging works by simple using transform.translate and will stop moving after a certain distance. The normal walking uses navmeshes and navmeshagents, however, it does not stop when within a specified distance to the target. I can’t find why the navmeshagent isn’t stopping, but transform.translate will stop.
Here’s some code:
public float distanceToTarget;
void Update()
{
distanceToTarget = Vector3.Distance(transform.position, target.transform.position);
}
void Dodging()
{
if (dodging)
{
If (distanceToTarget > 1)
{
transform.Translate(Vector3.forward * movementSpeed * Time.deltaTime);
}
}
}
void Walking()
{
if (distanceToTarget > 3)
{
agent.SetDestination(target.transform.position);
}
else
{
agent.isStopped = true;
}
}
So the Walking() function should keep updating the position of where to walk to as long as the player is more than 3 from the target, but, the player keeps moving towards the position of the target. For some reason it is completely ignoring the else statement when the distance is less than 3. I’ve set the distanceToTarget as public so I can watch the number go down, but even when it crosses the threshold of 3 it still keeps going down.
Does anyone know what is going on?