Question by
mdmiller002 · May 16, 2017 at 01:35 AM ·
ainavmeshnavmeshagentnavigation
Navigatin Mesh agent works for ~10 seconds, then starts moving sporadically
I have a NavMeshAgent guiding one of the enemies in my game, getting it to wander around, and my code works for like 10 seconds, the enemy moves around fine, however after that the enemy starts jumping around the nav mesh, sporadically, with no fluidity or anything. This is the code that is called in my update method to keep the enemy moving
private void enemyRoam()
{
Vector3 randomDirection = Random.insideUnitSphere * wanderRadius;
randomDirection += transform.position;
NavMeshHit hit;
NavMesh.SamplePosition(randomDirection, out hit, wanderRadius, -1);
Vector3 finalPosition = hit.position;
agent.destination = finalPosition;
}
Any ideas on why this would work for a few seconds and then start moving the enemy sporadically?
Thanks!
Comment
Your answer
Follow this Question
Related Questions
navmesh agent won't move on navmesh generated at runtime. 0 Answers
Farthest Reachable Destination 0 Answers
ai patrol and chase question 0 Answers
NavMeshLink don't work in correctly in certain area 0 Answers