Prevent player from moving off the mesh

Hi,
I am an absolute noob trying to make his first game and I needed some advice. I am making a game that involves a player and a maze. The maze will contain just the paths and none of the walls (imagine a floating road in space). I want to prevent the player from moving off the maze . I tried to create a simple version with a sphere and a plane and reached nowhere. My idea was to check for collision between the sphere and the ground and move everything back a frame if the collision ever stops. I could not find any similar examples though, so I’ve come here for help. I am sorry if this seems too basic but I am very new to this and would appreciate any help that you can offer

Hi @ignite and welcome to the forum. This playground (PG) should give you a start https://www.babylonjs-playground.com/#XZ0TH6#38

You must click on scene before using, w, a, s, d keys to move sphere.

Thank you! this is brilliant! I never even thought of using the raycaster. I really appreciate it.