Author Topic: whats the best way to keep an NPC inside a trigger  (Read 313 times)

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« on: July 11, 2011, 07:27:48 am »


                whats the best way to keep an NPC inside a trigger if they are not walking waypoints. I would rather not have to place down a waypoint and have them walk to it. Instead I was thinking of turning them around and having them walk in that direction then random walk. Does anyone know of a good way to do this or have a better solution?

Thanks
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« Reply #1 on: July 11, 2011, 07:52:57 am »


               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 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« Reply #2 on: July 11, 2011, 08:09:42 am »


               Thanks for the advice, I think I'll use the waypoint with trigger.
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« Reply #3 on: July 11, 2011, 08:58:15 pm »


               Create one waypoint, on heartbeat check distance, if greater then X, walk to waypoint, if not, randomly stroll around. No need for triggers.
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« Reply #4 on: July 11, 2011, 09:07:52 pm »


               Course, if its roughly a rectangle or circle, it's pretty easy to calculate a random point within those shapes to move to.

For a rectangle:
x = centrepoint.x + random(width) - width/2
y = centrepoint.y + random(height) - height/2

For a circle:
ang = random(360)
x = centrepoint.x + sin(ang) * random(radius)
y = centrepoint.y + cos(ang) * random(radius)
               
               

               


                     Modifié par _six, 11 juillet 2011 - 08:10 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
whats the best way to keep an NPC inside a trigger
« Reply #5 on: July 12, 2011, 01:10:02 am »


               There was the animal pen on the vault which I used, but found it not to be totally reliable.  So while the trigger waypoint idea is good it is not foolproof.  For my npc's who I want to stay in a general area I just put a bunch of wp's on the roads and mark them all the same, wp_road.  Then I just just use get nearest object by tag for them to walk too.  So they will just find the nearest wp road and walk to it.  If nothing interupts them then they will find the next wp road and walk to it.  Of course there are more complexities thrown in as I have them doing other things too, but that's another approach. Also I use onperception not hb, and instead of stipulating them to move on perception if only a PC comes around I just use a general GetLastPerceived so that anything can trigger this behavior.  Also I have them do other things on a switch to add some randomness.  While not the best answer to your question this, the above, does present a different way to approach this porblem.