Raycast Ignore Trigger Colliders
Published in
Aug 19, 2021
Objective: Allow a Raycast to ignore trigger colliders.
Our enemy has a player detection radius that is a trigger collider. When we cast our ray from the camera to the enemy, our shot is hitting that sphere. But there is a way to ignore all trigger colliders.
When we call Physics.Raycast, we can set the fifth parameter to QueryTriggerInteraction.Ignore. The nice thing about using using method over a layer mask is that it will ignore all trigger colliders everywhere! After all, we don’t our shot to stop at other trigger colliders such as pressure plates, item pick-ups, or proximity alarms!