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
whats the best way to keep an NPC inside a trigger
Débuté par
DM_Vecna
, juil. 11 2011 06:27
#1
Posté 11 juillet 2011 - 06:27
#2
Posté 11 juillet 2011 - 06:52
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.
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 .
#3
Posté 11 juillet 2011 - 07:09
Thanks for the advice, I think I'll use the waypoint with trigger.
#4
Posté 11 juillet 2011 - 07:58
Create one waypoint, on heartbeat check distance, if greater then X, walk to waypoint, if not, randomly stroll around. No need for triggers.
#5
Posté 11 juillet 2011 - 08:07
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)
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 .
#6
Posté 12 juillet 2011 - 12:10
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.





Retour en haut







