NPC navigation.

So, the documentation on the wiki for SNPC’s is pretty terrible. There is only one real example, with none of it explained, and a note that basically says don’t touch any of this.

After reading through some code, and Garry’s blog post, I’ve got a pretty good understanding of how the AI scheduling works. However, I’m unsure how to use it for my specific case.

I’ve got an npc that has an entity as a property. Call it MyTarget. MyTarget will move around the map, and I’d like the npc to follow MyTarget around. I thought about using TASK_SET_GOAL and then TASK_GET_PATH_TO_GOAL, but I’m not sure about how to pass MyTarget as the goal.

If anyone would like to point me in the right direction, here is the basic AI I am trying to implement.

Idle: Follow MyTarget around, staying within a certain distance of it.
Aggro: When an enemy moves into range, attack it. If the enemy moves outside of the range, or pursuing the enemy would cause the npc to move too far away from MyTarget, then switch back to Idle

Again, I’ve tried looking through the wiki, but the docs are terribad. :frowning:

Indeed, need lots of more documentation. If only people would know how to code npcs properly, I’m sure we would see lots of new cool stuff out there.

I’m not completely sure on the usage of SNPCs, but after working with them for a while, I’ve been able to figure out a method of making them move to a target. If I remember correctly there has to be AI nodes on the ground when telling an SNPC to go somewhere. I’m not completely sure that this’ll work for you, but this is about as much help as I can offer in this subject.

[lua]local schdChase = ai_schedule.New( “AIFighter Chase” )
schdChase:AddTask( “FindEnemy”, { Class = “mytarget”, Radius = 100000 } ) // Selects “mytarget” as an enemy for TASK_GET_PATH_TO_ENEMY
schdChase:EngTask( “TASK_GET_PATH_TO_ENEMY”, 0 ) // Finds a path to the target using nodes on the ground
schdChase:EngTask( “TASK_RUN_PATH_WITHIN_DIST”, 10 ) // Should run to 10 units away from the target
schdChase:EngTask( “TASK_WAIT_FOR_MOVEMENT”, 0 ) // Waits for the SNPC’s current movement to stop[/lua]



this:SetLastPosition( Vector(rv2[1], rv2[2], rv2[3]) )
this:SetSchedule( SCHED_FORCED_GO )


https://wiremod.svn.sourceforge.net/svnroot/wiremod/trunk/wire/lua/entities/gmod_wire_expression2/core/npc.lua

Thanks, I’ll give this a go tonight when I get off work.

This is just what I needed. Thanks