- Home /
Using raycasts and triggers
I have my enemy using a raycast to test line of sight but it's colliding with triggers that I have set up despite the layermask supposedly phasing these collisions out. If I remove the trigger aspect on the offending collider it does ignore that collision. I also know that I can remove all raycasts colliding with all triggers but I need that functionality elsewhere in my game. Is there any way to get this raycast to ignore a layer without making all raycasts ignore all triggers?
Have you tried using layer masks?
http://docs.unity3d.com/ScriptReference/Layer$$anonymous$$ask.html
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
I did but for some reason raycasts ignore layer masks if the object is a trigger.
Answer by Maniacbob · Apr 09, 2015 at 04:37 AM
In case anyone is interested. User layers won't work as masks for raycasts and triggers, but if you apply the Ignore Raycast layer to the trigger then it will ignore the trigger. Not sure why user defined layers won't work but whatever.