I’ve been having trouble getting IgnoreCollision to work. I have a gameobject called Barrier that is basically 4 boxColliders and a ship prefab with 3 boxcolliders. The following code happens in the ship initializing. I want the ship to be able to fly through the barrier. I’ve tried a lot of different things but so far nothing has worked. There has to be something I’m overlooking. Any ideas what I’m doing wrong?
var shipColliders = GetComponents(Collider);
wall = GameObject.Find("Barrier");
var wallColliders = wall.GetComponents(Collider);
for (var shipcol : Collider in shipColliders)
{
for (var wallcol : Collider in wallColliders)
{
Physics.IgnoreCollision(shipcol.collider , wallcol.collider);
}
}
colliders1 : Array = player.GetComponentsInChildren(Collider);
colliders2 : Array = barrier.GetComponentsInChildren(Collider);
for ( var c : Collider in colliders1 ) {
for ( var c2: Collider in colliders2 ) {
Physics.IgnoreCollision( c1, c2 );
}
}
That’s exactly how I get all the random stuff to not interact with my player, and it works for me.
Perhaps your Find operation isn’t returning the right object?
I know GameObject.Find(“Barrier”) is working. I was explicitly typecasting everything so I could check the values in the editor. That one I know was working. I’m not sure about the ship though. And I’m not sure what GetComponents is actually getting because I can’t set it up to check in the editor. Either way, when it does run with no errors, my ships are still colliding with an invisible wall.
I’ll try something closer to what you suggested when I get home tonight. Thanks for the help.
var barrier = GameObject.Find("Barrier");
var colliders1 : Array = GetComponentsInChildren(Collider);
var colliders2 : Array = barrier.GetComponentsInChildren(Collider);
for ( var c1 : Collider in colliders1 ) {
for ( var c2: Collider in colliders2 ) {
Physics.IgnoreCollision( c1, c2 );
Debug.Log(c1.name + " is ignoring " + c2.name);
}
}
The log shows all the collisions that I’m expecting. The other log you suggested looks like it’s getting everything it’s supposed to. There has to be something simple that I’m overlooking.
Thanks for the Debug.Log suggestion by the way. That’s helping out a lot.
Finally got it working when I added it after the instantiate function. So I just shoved everything in a newShip() function. I still don’t know why it doesn’t work from a script attached to the ship though. Thanks again for the help.