Need guidance on non physics movement and collision.

I’m relatively new to coding and am currently working on a board game project. Currently I’m stuck with trying to figure out the best way for the game tokens to stay within boundaries of a board. My code currently allows for a dice roll, and movement of 1 unity unit space based on arrow key direction.

Since the tokens aren’t being moved with physics I’m not entirely sure how to stop my tokens from walking through walls, because If I use a standard physics collision it will knock the token off of the world space points its moving along.

My initial thought was to code a trigger in walls that would reset the token to the last good position when it hits the collider, but I have this nagging feeling that there is a better way. Anyone in the community have any thoughts on this?

Hopefully I explained myself well enough and thanks for any assistance.

I think the most common alternative to using physics is raycasting. In case you’re not familiar with the concept, a raycast is basically a beam that fires from an origin point (like your game piece’s position) in a direction (like the direction of the arrow key the player presses) for some distance. With a raycast, you can either get info from the first object hit, or you can do a RaycastAll() and get a list of everything in the ray’s path. You can also use a layer mask to filter out layers that you want the raycast to ignore.

So when the player presses an arrow key, you could do a raycast in that direction, and if no obstruction is detected, then move the game piece.

There are also things like box cast, sphere cast, & rigidbody sweep tests if a raycast is too 1-dimensional for what you need.

Thanks guys. I appreciate the input. That sounds like it is exactly what I’m looking for. Gives me a place to start.