- Home /
Raycast2D ignore one object
Sorry if this has been asked before, I can't seem to find any solution that doesn't involve layers.
I want to raycast from the position of an object a certain distance and see what I hit. How can I make this not simply detect the object whose position I am starting out.
Layers are not suitable for this as lots of objects will be using the same behaviour to check collisions against objects of other types. I need to only ignore the one that is doing the ray check.
I would rather not do RaycastAll as this feels unnecessarily expensive when I am only interested in the first object that is not the object doing the raycast.
Answer by komodor · Jan 28, 2014 at 04:49 PM
i would http://docs.unity3d.com/Documentation/ScriptReference/Physics2D.RaycastAll.html and exclude the gameObject and I see you don't want to use it :)
another option might be to disable or move the object or just it's collider before raycast and then enable / put it back
Answer by JCX · Apr 07, 2014 at 11:18 PM
after some time i have another idea for solution
colliderToIgnore.enabled = false;
rh = Physics.Raycast(.....);
colliderToIgnore.enabled = true;
Your answer
![](https://koobas.hobune.stream/wayback/20220613131720im_/https://answers.unity.com/themes/thub/images/avi.jpg)