x


What might cause Physics.IgnoreCollision to not function?

I'm trying to do a very basic thing, have my turret not collide with the missiles it's launching. Missile is a prefab reference.

GameObject missile = (GameObject)Instantiate(Missile, centerTube.position, centerTube.rotation);
BoxCollider turretCollider = transform.Find("Ball").GetComponent<BoxCollider>();
Physics.IgnoreCollision(turretCollider, missile.collider);

The "Ball" child object is what the collider that's causing problems is actually attached to. There is another collider on the main GameObject but it's a trigger and used for activating the firing of the turret. Could having two colliders on different parts of a prefab hierarchy be causing issues? I've tried everything I can think of, even adding this to my Missile's behavior.

public void OnCollisionEnter(Collision other) {
    if(null != other.collider) {
        Physics.IgnoreCollision(collider, other.collider);
    }
}

But the instantiated missile is still effected by the box collider. Of course, turning that collider into a trigger makes everything work fine, no more collisions, but then that breaks everything else. Any ideas?

more ▼

asked Jan 27 '10 at 10:41 AM

dkoontz gravatar image

dkoontz
185 6 8 18

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The problem may be that if any objects have 'rigidbody' components, a rigidbody will use all the colliders (excep mesh colliders) on any of its child objects together as a single "compond collider". That is, unless the child object also has a rigidbody component, in which case the rigidbodies act as independently moving objects even though they have a parent-child relationship in the hierarchy.

So it could be that wherever your rigidbody component is (if you have one), it's greedily assuming that all child colliders should belong to it, and that may be causing confusion about which colliders should be ignored - or something like that!

Perhaps you could solve your problem by restructuring your hierarchy so that there's a separate gameobject with the trigger collider used for activating the firing, and make that entirely separate from the turret itself in the hierarchy.

more ▼

answered Jan 27 '10 at 11:31 AM

duck gravatar image

duck ♦♦
41k 92 148 415

Interesting, I didn't know a compound collider grabbed all the child colliders, good to know! Unfortunately there's no rigidbody on any part of my turret.

I will try the separate GameObject with the non-trigger collider to see if I can get IgnoreColliders to function with that configuration.

Jan 27 '10 at 07:28 PM dkoontz

Setting the child objects to have mesh colliders did resolve my problem.

Jan 31 '10 at 09:32 AM dkoontz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2505
x1880

asked: Jan 27 '10 at 10:41 AM

Seen: 2198 times

Last Updated: Jan 27 '10 at 10:41 AM