Garry's Mod Wiki



boolean NPC:NavSetRandomGoal( number minPathLength, Vector dir )


Creates a random path of specified minimum length between a closest start node and random node in the specified direction. This won't actually force the NPC to move.


1 number minPathLength
Minimum length of path in units
2 Vector dir
Unit vector pointing in the direction of the target random node


1 boolean
Whether path generation was successful or not


Example usage. Keep in mind that non scriptable NPCs will override their tasks occasionally. This is meant for scriptable NPCs

function MakeNPCGo( npc ) -- Choose a random node to go to at least 200 units away from us in the direction we are looking npc:NavSetRandomGoal( 200, npc:GetAimVector() ) -- At this point npc:GetPathDistanceToGoal() will return a different value, if a new path was generated -- Force us to go there -- 48 is TASK_RUN_PATH npc:StartEngineTask( 48, 0 ) end

Special Pages



Render Time: 70ms

DB GetPage 52
Generate Html 4
SaveChanges (1) 6
Render Body 0
Render Sidebar 6