- Home /
Compound Colliders and IgnoreCollisions
Ok, so game is about spaceships with guns. Nothing all that unique there. I instantiate bullets at the gun and I want them to ignore collisions with the ship firing them.
Ignoring collisions with transform.root helps but doesn't solve all the problems because all of my ships use compound colliders. Bullets are still colliding with the child colliders.
I want to ignore collisions with root and all of root's children. I don't want to name the colliders manually because some ships have more colliders than others. Advice?
One idea I've considdered but it is very clunky: each ship has a variable for how many colliders it has. We'll call it collNum create some list using a for loop in range collNum. Name all of my colliders "Colliderx" do some string manipulation where that list of numbers is now a list of 'Collider' + number do a find function on everything in that list. Ignore collisions with everything found. Is that really the best way to do it? I'd also need to make sure, then that I'm not ignoring collisions with other ships compound colliders.
Answer by efge · Mar 19, 2011 at 02:33 PM
You could use Layer-Based Collision Detection.
Wouldn't that mean I'd have to make every single ship it's own layer?
Thinking about it some more, It seems like for layer based collision detection to work in this case I'd need to form a new layer when I spawned a ship and then use code to ignore collisions with that layer. I'd not be able to use the inspector because the layer wouldn't exist until the ship spawned at runtime. Would this really be easier or less resource intensive than the string shennanigans described above?
Depends on how you treat friendly fire in general. If you have to opponents, two collision layers might be sufficient. It's very much depending on your scenario.