- Home /
Best practice to make NavMeshAgent chase a moving target?
I know how to make an agent to reach a static point on the navmesh (Make a wander arround behaviour). I know how to make an agent move following User's input (Player movement).
Instead, my question is more efficiency related. I can achieve a chasing behaviour by telling an enemy-agent to reach player's position, and update the position every time interval. But this approach does not convince me in any way. If the interval is to wide, the enemy looks foolish; and if the interval is to short, it's too processor intensive (as it has to recalculate the path every interval).
So, if I have to use Unity's NavMesh system and need to make enemies chase my moving player, which is the best approach?
Sometimes it's simpler to just not optimize. If you don't have many agents, the performance drop won't be noticeable.
Answer by Multirezonator · Nov 29, 2017 at 04:04 PM
Do not recalculate path every frame. I think enough 10 per second when enemy near player and then, the farther enemy from the player then the less necessity to update the ways. Try to experiment with update interval based on distance from player.
If you check, I talk about "time intervals", I never assumed doing the recalculation every frame. The idea already frightens me. Although the distance dependent interval is interesting, what I want to discover is if there is a different and more efficient approach. (BTW thanks for the answer @$$anonymous$$ultirezonator!)
Have you found any? I also don't like an enormous amount of entities to recalculate a path every second...