Smart movement of gameobject in a maze

I’m making a sort of maze game, but at the loading screen, I want to make a sphere go thru a maze. But not a programmed path, so I can create random mazes without having to make a path for each.

I want to let it turn (example) right when there isn’t a wall right, there is a wall in front of it, and a wall left. Also when there aren’t walls right and left, for it to choose one. I’m trying hard but can’t do it, I’ve tried colliders and Rays. I don’t know which is best to use.

If you know how to do this, please help me. If you send me some code of how it should work, that would be awesome, I could learn a lot from that! And if you need any more information, ask below this!


Well if you aren’t as concerned with actually solving the maze, you could generate your maze based on nodes.

For example, each node has 4 directions, or walls. When each node generates, those 4 walls will take on a state: closed or open. From there, it’s just a matter of traversing the nodes with your sphere by choosing a random direction at each node.

If you actually want to solve the maze, say the sphere traverses the path and finishes it when you hit 100% loaded, your going to need a pathfinding algorithm, something I am far from adept at, but here’s a cool video by Computerphile that talks about this node systems and solving mazes.