In my 2D tetris like game i want to make borders where tiles (game pieces) can’t move. Tiles are moved by mouse.
On tile i added Box Collider 2D and Rigid Body 2D, same components i added to border.
But when i drag a tile it doesn’t collide with border, it goes through.
When i add gravity to the tile - so after game is start tiles start falling down - tiles start colliding with borders. But when it all fall down to bottom border and i drag a tile it again doesn’t collide with border.
On a tile i have a script to move tile when it’s dragged. So when i drag the tile to border position tile move there even there are colliders.
Is there any chance how to create borders with the way i tried? Or is there any good practice how to create borders using 2D physics?
Tile is moved by mouse (input.mousePosition). So if mouse is over border then tile move there too. But i thought the colliders won’t allow move of tile over the border. But it makes sence…
So is there any good practice how to create borders with using of unity components without scripting?
Now when i drag the tile i must check if every side (border) of tile is not in the position of the border. It seems to be uneffective a quite difficult.
My current solution:
a) border has a box collider
b) tile has a box collider and a rigid body
c) tile is moved by intput.mouse, but instead of using transform.position i use Rigidbody2D.MovePosition
It works well for me but i’m not sure if it’s a good solution.
If there is a better way to solve it reply please.