- Home /
How do I make a prefab ignore collisions with another prefab temporarily.
I am currently working on a platformer game that involves a death animation once the player has run out of health. I am wanting the player to be able to ignore 2d collisions with an enemy, as it is going through the animation. I have already tried using the code: Physics2D.IgnoreCollision(Player.GetComponent(), Enemy.GetComponent());
But this only works for a single enemy not all of them. I have attached the enemy prefab to the player under a game object, but still no luck.
Appreciate the Help
Answer by mustafacomert00 · Aug 25, 2021 at 08:57 AM
Set different layers for enemy and player,
when animations starts:
Physics2D.IgnoreLayerCollision (playerLayer, enemyLayer, true)
when the animation ends:
Physics2D.IgnoreLayerCollision (playerLayer, enemyLayer, false)
Answer by joan_stark · Aug 24, 2021 at 08:43 PM
In your animation, you can simply disable the player collider, and then re-enable it after your animation is finished.
The only problem is that my box collider deter$$anonymous$$es whether or not the player stays on the platform, if I disable it the player just phases through into the void. Any ways around this?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Object Reference not set to instance of an object - error in 2d rope code 0 Answers
The New 2D Pixel Perfect Camera Package "Stretch Fill" Causes Major Lag 0 Answers
What can I do to further optimize mobile game? (2D) 0 Answers