- Home /
raycast ignore trigger colliders?
Hi. I am currently working on an fps game. I have created some triggers for instantiating enemies and sound effects. I have also created a weapon script that uses raycast to instantiate bullet hole prefabs, knock rigidbodies over and send a damage message to the enemies. My triggers block the raycast message and instantiate a bullethole in mid-air if I shoot at them. How do i make the raycast completely ignore the trigger colliders?
Answer by Okido · Mar 04, 2014 at 01:41 AM
To have your raycasts ignore all trigger colliders in 5.2 and up, go to (still correct in Unity 2021):
Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers"
(If you're using an older version of Unity, the check box is called "Raycasts Hit Triggers")
I know this is an old topic, but seeing as its the first result when googling the problem it should still be helpful.
Very handy if you got 2 colliders on one game object like I have.
You just saved my day. I have fire triggers and also coins in my 2D sidescroller, and I was trying to make a ray that checks if you can stand up after a crouch.
Do you know? Do you have any idea? DO YOU $$anonymous$$NOW HOW THAN$$anonymous$$FUL I A$$anonymous$$ FOR THIS ACTUALLY WOR$$anonymous$$ING?
Thanks.
Supplying QueryTriggerInteraction.Ignore in the raycast call is a more flexible solution, like mentioned below by Anders$$anonymous$$almgren :)
Answer by AndersMalmgren · Jun 07, 2017 at 01:41 PM
If you have alot of raycasting third party libraries it can be dangerous chaning the global setting like Okido suggest. Instead supply QueryTriggerInteraction.Ignore
to the raycast method
Usage example: var wasHit = Physics.Raycast (origin, direction, out result, maxDistance, -5, QueryTriggerInteraction.Ignore)
This should be the accepted answer. Have alot of issues with third parties and plugins in the past. Thanks for this.
Answer by SpaceManDan · Oct 06, 2015 at 03:11 AM
Actually in version 5.2.0f3 it no longer says Raycasts... It now appears as: "Queries Hit Triggers" Uncheck if you want raycasts to pass through trigger colliders.
Answer by hameed-ullah-jan · Oct 24, 2018 at 11:37 AM
you can use the last parameter of the raycast function, put this "QueryTriggerInteraction.Ignore" as the last parameter in the raycast function.
Answer by ajdrew81 · Aug 11, 2015 at 02:00 AM
I recently had a similar problem.
Go to Edit -> Project Settings -> Physics2d and Uncheck the box that says "Raycasts Start In Colliders".
This will let you ignore the colliders on the gameobject casting them. This makes it so that you do not have to deal with layers (I find layers to be a very impractical way of selectively raycasting). It just ignores the collider on the gameobject casting the ray, so you can have multiple prefabs of players/enemies casting rays and hitting each other, but not themselves.
However, to ignore trigger colliders, please use Okido's suggestion.