I am working on a top down 2d game where I want the player which is the white circle, to walk on the tilemap grid by grid when pressing WASD, and stop when there is a wall or an enemy in front of the direction it is walking. The problem is that even I add box collider 2d and rigidbody on both the player and the enemy, the raycast cast from the player to the direction it is going one block away, never hits the enemy, so the player will just go through the enemy. However the raycast does detect the walls that have tilemap collider 2d on.
(https://i.sstatic.net/DKyy2u4E.png)
At first I thought it is the collider is having a bit overlap when the player and the enemy is standing next to each other, so I reduce the size of the collider from 1 to 0.8 for both player and enemy, but it still doesn’t work.
user26436276 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.