- Home /
Implement auto-run using Nav Mesh Agent
i am trying to implement auto-run on my player; the player is using click-to-move: ray cast to a point on the terrain and set that point as the destination. Simple.
I am really struggling to get the character to keep moving forward at a constant rate. The closest I have come is the following, but it fails when terrain is not flat or if there are obstacles; the player bumps around, changes direction, or stops in those cases.
Once I hit an invalid patch of the navmesh it stops working. This makes sense, but what I am really trying to do is just keep the player plowing forward no matter what and never changing direction; just like basically every MMORPG that has an auto-run function.
Is there another approach to do this using the Nav Mesh Agent and click-to-move-like movement? I played around with the Move method but failed miserably and it doesn't really seem to be documented in the Unity Docs.
if ( autoRun )
{
playerNavMeshAgent.SetDestination( this.transform.position + this.transform.forward );
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613041718im_/https://answers.unity.com/themes/thub/images/avi.jpg)