- Home /
Waypoint System help
Hello,
I have my enemy that follows the player around when he gets into a certain range. When there is no target nearby/if he loses/kills the target, he should walk aimlessly around. When he is walking around, he should pick a random nearby waypoint, go to it, then pick another, go to it, and repeat. How would I do this? I have thought to have a bunch of waypoints that each have a list of other waypoints they connect to, but there must be a quicker way.
All help is appreciated,
Thanks,
Thor
Answer by Travis-Bulford · Jul 01, 2013 at 03:37 PM
Hi Thor,
You can consider using Random to generate a way-point from your current point.
Assuming your point would be x,z and y is the altitude you could great a Vector3(x+Random.value*20f-10f,-WAYABOVETERRAINT,z+Random.value*20f-10f) way above the terrain and ray-cast down to get the y at the coordinate. (One issue will be if there is a suitable path to that point.
Generally we try keep tack of our mobs home point if the chasing the player they will return to there "home" location before roaming. Then roaming random points would only be generated within a radius of there home point. (you can do this easily with some trig, generate a random angle and radius from home then do the above ray-cast to find the complete vector.) A more sophisticated roam would only adjust the current movement angle always tending towards the home location but not completely rotating.
Without more information of your game world environment it will be difficult to give more advice.
The environment has many stairs, so there won't be a suitable path to most points. It is basically a city, so there are a ton of buildings that the enemies can go up stairs on. I hope that helps. Thanks
How do you path find? Are you using a node based a* solution? If so you could search nodes nearby 2 or 3 at a time the first that's path-able use that.