- Home /
Ignoring the raycast of a child collider but not parent.
I have a sphere collider attached to an empty gameobject, i set this sphere collider as a trigger, and also the gameobject as a child to its parent, i want to be able to raycast the parent but not the child node, the problem is.. that if I ignore layer of the collider, it then ignores anything inside the collider, but this is an aiming thing, so i cant just simply redirect to the parent, because then u could shoot anywhere on the childs bubble to hurt the parent; so any suggestion on how one might bypass this enigma?
Answer by Seth-Bergman · Jul 27, 2012 at 09:18 AM
just give them each a unique tag, and use RaycastAll to find what you want based on the tag:
function Update () {
var hits : RaycastHit[];
hits = Physics.RaycastAll (transform.position, transform.forward, 100.0);
for (var i = 0;i < hits.Length; i++) {
var hit : RaycastHit = hits[i];
if(hit.collider.tag == "parent"){
//do something
}
...etc
good enough, was hoping to not have to allocate that much and loop through each update, but I guess if that is the only way.
well, I'm thinking you probably COULD use a layermask ins$$anonymous$$d, child objects can be on separate layers than their parent, so I would think that would work
Answer by delpontej · Feb 12, 2013 at 11:19 AM
In Unity 3.5 at least setting the child node to the 'Ignore Raycast' layer will solve this problem for you without needing to perform extra loops.