NPC Finding players.

I’m currently working on my own gamemode from scratch purely for educational purposes and have come across a tricky subject.
I wish to have NPC’s spawn at certain locations around the map (close to humans, but not within view distance, eg; around corners out of roofs so on so forth).

I’m just stuck on how I would go about getting an NPC to follow a path and find a human. I’ve taken a look at gm_navigation and feel it might be of use, just not sure where to go from here.

Any help is appreciated,


Haven’t tinkered around with gm_navigation, but you should first create the grid with nav.CreateNav(X) and store the object that it returns.
Then you do Nav:SetStart( Nav:GetClosestNode( NPCPOSITION ) ).
And then, Nav:SetEnd( Nav:GetClosestNode( PLAYERPOSITION ) ).
And, to calculate the path, you use
[lua]Nav:FindPathHull( npcmins, npcmaxs,
function(Nav, FoundPath, Path)
<movenpcalong Path>
end )
Take the first node in Path, do “Node:GetPos()” and make the NPC run there, then you do the same with the next node, untill he has reached the target.

As said, I have never used this module, but this should work if the documentation is correct.

You also need to do some code at FoundPath to make sure a path was found, if it wasn’t, place the NPC somewhere else.

Thank you for the quick reply Donkie, logically it seems to make sense.

I’ll give it a whirl when I get a chance next.

Thank you again.