Pathfinding & Waypoints System


Long overdo post on the pathfinding and navigation systems. 

Essentially, all I did was implement an A* pathfinding algorithm. I already had some familiarity with how it works, but not the nitty-gritty of how to implement it. So I followed a video series on YouTube by Sebastian Lague (highly-recommend channel, by the way) to learn about it. His implementation did most of the things our game needed, so I coded along with most of it; however, his system works with diagonal movement, whereas our doesn't, so I had to slightly adapt the function that detects cell neighbors. Basically, I just skip the for-loop cycles that look at diagonal cells (see below).


Alongside that, I created a system that automatically adds cells occupied with colliders to our node system. 

Next, I had to collect a list of cells in the path found and create waypoints at the appropriate coordinates. The (previously created) movement script would then take care of sequencing the moves from waypoint to waypoint until the agent reached its destination. Logically, a waypoint should be set a the final destination as well as at any cell in which the direction of movement changes. Here's a look at the code implementation:


At this stage, without any fancy graphics, this is what that looked like:

Eventually (months later), with graphics implemented:


Files

ToyboxAdventure_v0.1.zip 21 MB
Apr 20, 2021

Get Toybox Adventure

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.