I'm doing a simple grid based game, where the player should only be able to move on the grey cells. It works quite ok, but in this simple scenario, the player is able to walk through Wall(1), although there is a collider on it and I'm checking with a raycast before moving. When removing the (nonblocking) pickup, the collider works. I'm assuming, the raycast is hitting the collider of the pickup, when the player is on that position and therefor misses the collision with the wall. What is a good practice to handle this issue?

grid based player movement

  • \$\begingroup\$ I am gonna need some more informations: 1. Can we see the walls' colliders? 2. What are the layers of each collider and how does the layer matrix look like? 3. Where does the raycast start from? 4. Does your player goes from the position you are showing to the behind the wall position in one move? 5. Is the pickup's collider a trigger? \$\endgroup\$
    – Alakanu
    Oct 24, 2017 at 10:35
  • 1
    \$\begingroup\$ If you've solved your issue, please consider posting your solution as an answer (and marking it accepted after the short waiting period) so other users can learn from your experience. :) \$\endgroup\$
    – DMGregory
    Oct 24, 2017 at 13:31

1 Answer 1


The best way is probably to or use different layers to differentiate between collectibles and obstacles. In the raycast function you can use the layerMask parameter to include only the layers you want to check.

An alternative is to use RaycastAll to get a list of collisions to check for your obstacles.

  • \$\begingroup\$ actually I am using different layers (blockinglayer for walls, obstacles and default for anything else) Thank you for the advice, i used another signature of linecast including the blockinglayer index, which worked for me. answers.unity3d.com/questions/840614/… \$\endgroup\$ Oct 24, 2017 at 8:26
  • \$\begingroup\$ @user2819446 excellent! So the issue is solved? \$\endgroup\$
    – Dege
    Oct 24, 2017 at 8:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .