A random maze generation, with keys for the bot collect and unlock exit.
This project was made to practice Maze Generation Algorithm, to understand how it works and his implementation. After that, to use the maze for something, I decide to create a simple bot that would try to escape from maze.
To this project I used the RayCast class from Unity, to detect and find the best direction to bot moves, then eventualy unlock and go to maze exit. However isn't best form, but is simple and can be useful, case you want that bot goes to diferent paths before exit from maze.
To find the bester and faster path to exit is common use the Dijkstra's Algorithm, a powerfull Pathfinding algorithm.
"Where you can find the shortest path between nodes in a graph. Particularly, you can find the shortest path from a node (called the "source node") to all other nodes in the graph, producing a shortest-path tree".
You can implement it, modify and at the end get something similary or even better that using raycast.
Every movement of bot is tracked, like paths that he already completed(where there aren't keys anymore), current walked path and the maze exit when he find it.
- Completed 🟩
- Maze exit path 🟦
- Maze exit point ⬛
- Bot 🟥
- Keys 🟡
"Current walked path" its just a reference for bot, it isn't dreawed.
To up, down, left and right of the bot, it has a line RayCast with a maximum distance set to one, it is used to get a GameObject collider, like:
- Wall;
- Key;
- Maze exit;
- Or return null, if don't colliede with nothing.
Using this data, the bot recive a direction to move, taking into account some rules, he:
- Can't back to walked path until it resets(it reset when, all the possible directions are blocked);
- Can't enter in completed path;
- Can't exit from maze until collect all keys;
- Always collect keys detected by RayCast;