Log In  

Cart #heatmappath-2 | 2020-09-19 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

I just finished this method for path finding that I will implement in my other projects.
This method is resizable and really easy to implement and understand.
I spent the last day concocting this.
Essentially it creates a heat map/height map of costs that can be traversed by agents by referencing the node list.
Press X to place walls or remove them.
Press Z to set the end node to the nearest node to the on-screen cursor.
Cursor controlled with arrow keys.

The method works this way:
Create an empty list for checked nodes. We will push nodes into and out of it. Any node inside is there only temporarily.
We start with the first node, set it to visited, and put its neighbors into the checkedNodes list.
While the length of list of checkedNodes is bigger than 0, check all neighbors of all nodes in list, and pop out nodes from list that were visited. Only new nodes get added in. Any node after checked is removed.
This creates a cascade effect that fills the entire possible connected set of nodes with costs.

To traverse it, simply find the nearest node in world space to your agent, and check the neighbors and find the one with the lowest cost, set that to your next movement target, and move to it. If you get to the end node, stop moving. If the node the agent is on has no neighbors, also don't do anything.

I made it so you can give it a grid size at the top of the code using the SIZE variable, and it will make it just work.

And there you go. Hope you like it.

P#81986 2020-09-19 10:12

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-10-21 16:16 | 0.017s | 2097k | Q:27