- Home /
Ignore Collision Temporarily
I need an object to have no collision with the player while is is being scaled. This is because while it is growing, it is causing to launch the player. I have tried using :
if(transform.localScale.x < 1 && Growing)
{
transform.localScale.x += GrowTime;
transform.localScale.y += GrowTime;
transform.localScale.z += GrowTime;
Physics.IgnoreCollision(gameObject.FindWithTag("Player").transform.collider , this.collider);
}
while the variable growing is set to true. But once it is set to false, the player can still not collide with the Object. Is there any way to make the object start checking for collision again once growing is set to false?
Answer by kromenak · Mar 22, 2012 at 01:31 AM
You should be able to use Physics.IgnoreCollision to do this, as you've got. I'd use the third parameter to be explicit about it. Based on the documentation, you should be able to do IgnoreCollision(collider1, collider2, false) to regain collision. I have used this in the past, so should work unless something is up with 3.5.
If that doesn't work, the documentation also mentions that you can Deactivate/Reactivate the collider objects to clear the IgnoreCollision state. See here: http://unity3d.com/support/documentation/ScriptReference/Physics.IgnoreCollision.html
Good luck!
Your answer
Follow this Question
Related Questions
Detecting When Intersection Penalty is Being Applied 2 Answers
How to properly move a rigidbody/collider? 2 Answers
Collider2D that not collides 1 Answer
How do I get the player and the object they touch both disappear/destroyed? 1 Answer
Collisions between two rigidbody's and scripting collisions problem 2 Answers