- Home /
Mouse drag through Maze without relying on collision
Hey everyone
We are currently working on a puzzle game that involves a cube you can rotate. On the cube you can find several puzzles you have to solve to slowly deconstruct the cube.
For one of the puzzles we designed and modeled a 3D Maze that you are supposed to drag several objects through along different paths to the center.
To code a function that allowed us to drag the object via mouse wan't an issue but we dont know how to make sure that the Player has to stay within the boundaries of the path. We could do this with physics using collision but since that's prone to glitches we would like to find a different approach.
Has anybody any idea how to approach this? c# would be preferred since none of us have worked with JavaScript before
Thank you
Answer by Koyemsi · May 11, 2021 at 02:07 PM
The first thing I think of would be using Unity's navigation and pathfinding system. The floor (being marked "Navigation static") and the walls of your maze would define a navmesh. Your ball would be given the Navmesh Agent component. You wouldn't drag the ball itself, but a "dummy" object (not visible).
At runtime, the ball would move to the closest location on the path near the dragged dummy, without having to worry about collisions or physics.
See documentation : https://docs.unity3d.com/Manual/Navigation.html
Thanks a lot, this seems to have been the solution we were looking for. We made the maze "Not walkable" and have the Agent move towards our cursor with OnMouseDown. You helped us a lot
Great, I'm really glad I could help ! I hope to play your game someday, and when it comes to the maze, I can proudly strut and say : "hey, it's me who told them how to do that" ;)
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
How can the player position updates randomly when the player isn't movingl? 0 Answers
OnCollisionExit problem 1 Answer
isKinematic object doesnt collide with wall 3 Answers
Jump on the ground 2 Answers