- Home /
walking through the countryside ?
I want my characters to walk from village to village, maybe seemingly at random (hopefully my AI will provide a reason for their journey), however the entity travels in straight lines to the waypoint. How can I get my characters to walk along roads or footpaths that I will create?
What you need is a weighted pathfinding. Take a look at this excellent tutorial on A* if you're new to pathfinding. Otherwise, just add a weight to your nodes which is added in the heuristics calculation.
Note: A* doesn't handle "complex" shapes very well (shapes where the final path will be counter-intuitive (e.g. you have to walk further away from the goal node until you can turn and go back to the goal node), so I can recommend using a bi-directional search.
Answer by OneCept-Games · Jan 05, 2018 at 04:23 PM
You could use Unity's build in Navigation and Pathfinding module. You could also create your own Waypoint system, which is simply just an Array of Vector2 or -3 objects, and then move your object along this route, even implement some Spline/Bezier curve math.
Sounds cool - I was wondering if there was a way to use the navmesh - put a weighting on the scenery. like crass and dirt, etc, then the pathway would prove to be quicker due to being a lower weight?
Then a simple Waypoint system might be better in your case. There ar several tutorials and assets on Unity Asset Store that should solve your problem.
but thats the point - with 100s of NPCs going about their business, the waypoint flags will be massively complex over several cities and the connecting roads and trails - im after something navmesh like that i can se a way point in a building in the next town and the entity will wander through the streets to the edge of town, take the best trail (NOT AS THE CROW FLIES) and head to the next town, down the alley ways till it gets to the allotted place.