The best way really is just to have them move back to a waypoint/object if they leave the trigger(OnExit). It doesn't have to be right at the waypoint/object. You can just make them move back within a certain distance of the object.
Turning them around and using functions to determine "behind locations" or what not, via the OnExit event, can cause problems. Think of the NPC in a corner of a square trigger and they are leaving the corner at an angle and then you might turn them around and move them only to go right back out of the trigger and repeat the same thing. They can get stuck. So you would have to determine a location more in the center of the trigger and move them to that location but then that would just be pretty much the same as having them move to a waypoint/object.
Another option, though not as efficient, would be to do away with the trigger all together and use the NPC heartbeat to check how far they are away from an object/waypoint. If they are too far then move them back and start the random walk again.
Modifié par GhostOfGod, 11 juillet 2011 - 06:57 .