Missile colliding with Character Controller

Hello all,

I'm creating a missile via script attached to the first person controller. The only problem is that my missile collides with the character controller's collider before it moves anywhere. I've tried to use Physics.ignoreCollision() but it doesn't seem to work with the character controller.

function FireRocket () {
    var rocketClone : Rigidbody Instantiate(rocket, transform.position + Vector3 (0, 3, 0), transform.rotation);
    Physics.IgnoreCollision(rocketClone.collider, transform.root.GetComponent(CharacterController).collider);
...

I've used some printouts and determined that the missile is indeed colliding with the "CharacterController"

    Physics.IgnoreCollision(rocketClone.collider, transform.root.collider);

doesn't work either.

Any ideas? I could use layers, but I'd rather do it without them.

EDIT: I've done more testing, and my IgnoreCollision call points to the exact same object/collider that is colliding with my missile. I really don't understand why this isn't working.

Physics.IgnoreCollision(rocketClone.collider, transform.GetComponent(CharacterController).collider);

^^is the call that I'm using now, just to avoid any confusion. (they all should point to the same collider anyway)

Cheers,

Unislash

This turned out to be a very tricky problem. It turns out that my missile is a prefab, and has a core child for creating particles. The core for some reason had a box collider on it.

It appears that unity interprets any child collider as a collision with the parent too, so that was setting off the collision with the character controller--even though I turned the parent collider's collision with the character controller off.

I hope this helps someone, because it took me >4 hours to find this one!

Cheers,

Unislash

`Instantiate()` your missile farther away?

transform.root.collider would only work if this rocket was a child of the player object, and thats not something you want to do (the rocket would move around when the player moved around).

You'll have to cache a reference to the player in this script somehow, probably by making a

public var player : GameObject;

And dragging your player object from the scene to this exposed var in the inspector. Then use IgnoreCollision on the player's collider from there:

Physics.IgnoreCollision(rocketClone.collider, player.collider);