Garry's Mod Wiki

NPC:NavSetRandomGoal

boolean NPC:NavSetRandomGoal( number minPathLength, Vector dir )

Description

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.

Arguments

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

Returns

1 boolean
Whether path generation was successful or not

Example

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

Page Links


Special Pages


Wikis

?

Render Time: 90ms

DB GetPage 59
Generate Html 5
SaveChanges (1) 11
Render Body 0
Render Sidebar 12