Ignoring Collisions Problem

I am using the Physics.IgnoreCollision to selectively choose whether or not two objects collide. Now the issue I am running into is that the first moment the two objects interface they interact and then after that they don’t. It seems to be speed dependent because it isn’t noticable if they collide slowly but the faster they collide the great the effect is. I guess my question is how can I fix this?

This is the code I am using:

function OnCollisionEnter (other : Collision) 
{ 
	if(other.gameObject.tag == "WNonColl")
	{
		Physics.IgnoreCollision(other.collider, collider);
	}
}

function OnCollisionStay (other : Collision)
{
	if(other.gameObject.tag == "WNonColl")
	{
		Physics.IgnoreCollision(other.collider, collider);
	}
}

This is just basically checking to see if the tag of the object it is colliding with is “WNonColl.” If it is, it ignores the collision otherwise standard physics apply.

I have a test web player scene attached that will hopefully show you what I mean about this momentary interation. Any thoughts would be greatly appriciated. Thanks in advance!

57656–2093–$ignore_collisions_585.zip (27.6 KB)

One thing I forgot to mention something that is very important. I am using Unity 1.6.2, sorry about that. Thanks again.

Ideally you should be using Physics.IgnoreCollision() before two objects collide. It sets a permanent flag to prevent future collisions (until you call the function again and pass in false).

You could also add the relative velocity of the collision back onto the object, but really you should ignore collision before anything happens.

Hey thanks Matthew for the response. For some reason that didn’t occur to me though thinking about it that is the obvious answer, I just needed that jump start to get things rolling properly. Using that idea and this:

http://forum.unity3d.com/viewtopic.php?t=7626

I came to my final solution:

var nonCollisions : GameObject[]; 

function Start() 
{    
	nonCollisions = GameObject.FindGameObjectsWithTag ("WNonColl"); 
	
	for (var go : GameObject in nonCollisions) 
	{ 
 		Physics.IgnoreCollision(go.collider, collider); 
	}
}

Simple and does the trick perfectly. :smile: