2D Character Controller that only allows sliding against walls
Hello, new to Unity and C# and I'm looking for a nudge in the right direction.
Here is an example of what I'm looking to do - this was coded in GM (not by myself) very quickly, I couldn't figure out how to translate what was going on in that language to C#.
I'm working on a 2D game where the player controls a cube that can only move along the walls inside of an enclosed box. The character cube does not rotate. I've had no problem getting my character to move within the space and collide with walls, but I'm not so sure what the best way might be to limit my character to never leave the walls.
For me, the easiest solution seems like something along the lines of limiting the character to just move along a pre-set, invisible "rail" system, but had trouble finding any information about setting something like this up. Is there something I can look into to help me with this? Or maybe there's an easier solution I am overlooking, and I can research more if anyone has a suggestion.
Not looking for a complete script or an asset from the store, just some guidance... and if there's anything out there that might help me get started with my "invisible rail" idea. Thank you for any help!