Hi,
I would kindly like to ask for some general orientation for a small game we’re trying to build with my son as a learning project. Our knowledge of Unity is non-zero but pretty limited.
The game has pieces which can be thought as rigid blocks in a game board. Think like Domino pieces or cubes. These pieces can be moved by the player in different directions, using keys, but always in fixed units or cells. E.g.: move left, all pieces shift left by one position.
Now if there is something blocking the movement, the piece shouldn’t move. E.g. if there is a wall, then free pieces that can move will move, but pieces adjacent to the wall will stay in the same place. If the player keeps pressing the left key, all the blocks will end up adjacent to the wall.
We were able to get the basic movement working with a simple script by simply adding the fixed amount of distance to the transform.position of the gameObject on every key press. Where we are stuck now is: how to implement the movement from not happening if the path is blocked?
We tried initially by using Raycast to decide if there will be a collision before doing the movement, but that prevents two consecutive blocks which are free to move otherwise from moving: the block to the right will think that the block to the left is going to collide so it doesn’t move, and only the left one moves.
This makes me think that doing these calculations by hand will be complicated enough that it may be easier to use the Unity physics engine to check and enforce collisions instead. But how can we set-up the physics system in such a way that blocks won’t “bounce” when colliding, ending in different positions than the fixed cells where we want them? We’ve randomly tried different things such as very high mass or Drag but it always results in pretty strange behaviors.
I am almost sure we must be approaching the design in the wrong way. We would greatly appreciate some directional guidance or known tutorials to help implement this type of mechanics with Unity - we’ve searched quite a bit before posting but clearly there’s not thing easy to find or we suck at searching, most likely the latter.
Thanks for any suggestions,
Julian and Luqui