- Home /
Recalculating collisions after Physics2D.IgnoreLayerCollision()?
I have my "player" gameObject standing atop a platform. He press a combination of keys, I verify that he's standing on the right top of platform, and I run this code:
Physics2D.IgnoreLayerCollision(playerLayer, plataformLayer);
The intention being that he'd drop down from the platform. Instead, nothing happen immediately. The player is still atop the platform and can move around - only if he gets out of it and tries to get back to it, only at that point will he fall down from it.
So I made a temporary ugly workaround:
Physics2D.IgnoreLayerCollision(playerLayer, plataformLayer);
rigidbody2D.AddForce(transform.up * jump / 1.5f);
This will force the player to jump, making Unity "recalculate" the collisions and the player will, as I want to, pass through the platform. The even weirder part is: if the jump isn't high enough (100 force at 1 mass with 0.5 gravity scale seems to be the minimum), the player will still land on the platform, even though Unity is supposed to be ignoring those collisions.
I also tried pushing the player downwards, both with force and direct velocity, but no luck - he still collides with the platform, he only stops colliding with it after being away from it once.
Also, my player Rigidbody2D Detection Mode is set to Continuous, and I tried setting the platform up in many different ways, with and without a Rigidbody2D.
Any ideas on how to make the player instantly fall down from the platform as soon as collisions start being ignored? Thanks in advance.
Answer by sumiguchi · May 18, 2014 at 08:13 PM
Whydoidoit's comment worked out to be the right answer for me:
Physics2D.IgnoreLayerCollision (LayerMask.NameToLayer ("Ground"), LayerMask.NameToLayer ("Player"), true);
_rigidbody.collider2D.enabled = false;
_rigidbody.collider2D.enabled = true;
I was stuck on this for at least an hour - thanks whydoidoit!!!
Your answer
Follow this Question
Related Questions
Is it possible to disable collisions for separate physics scene? 0 Answers
Reset Rigidbody2D rotation after collision 2 Answers
How to make physics relative to moving parent 1 Answer
Rigidbody2D: Follow other Rigidbody2D strictly 1 Answer
Inconsistent gravity/random forces/solver problem? (forum crosspost) 0 Answers