Raycast avoiding spesific colliders

Hello everyone. I have a trainin scene in my game, and player should not pass through a spesific line. So I made a cube and make it invisible to prevent player passing from there. But player is supposed shoot the target which are back of that cube. When I shoot the targets are not being hit because of the cube that I made for preventing the player’s movement. I need to tell my raycast not to detect the cubes collider, but to detect the targets collider. Is here any way to categorize the colliders for raycast ? Thanks :slight_smile:

This can be controlled by placing the objects onto specific layers. Unity includes a layer by default called IgnoreRaycast. Try assigning that to your cube.

Failing that you can use a specific layer mask when performing a raycast to indicate which layers are to be included manually.

I would realize something like that with Layers & Tags:

http://unity3d.com/support/documentation/Components/Tags.html

http://unity3d.com/support/documentation/Components/Layers.html