- Home /
Using IgnoreLayerCollision and IgnoreCollision together
so currently I have something to ignore collisions between NPCs and the player, which works nice enough.
it disables collision individually for each NPC when the game starts (using Physics2D.IgnoreCollision()) and reenables the collision if the player or another NPC comes from above a NPC. It detects via a trigger on a child object above each NPC (so they can "climb" each other).
the thing is, it worked pretty well, but I was having some performance issues for using too many GetComponent() when the game restarted ( a mechanic), so I tried using ignore layer collision:
void Start () {
Physics2D.IgnoreLayerCollision(8,8);
Physics2D.IgnoreLayerCollision(9,8);
}
but after that using this stopped working:
Physics2D.IgnoreCollision (ourCol, other.GetComponentInParent<Collider2D>(), false);
I tried using a third layer assignment, but whenever an NPC is above another (changed to third layer, enabled collision), it also starts colliding with the player (should not happen).
Am I doing something wrong elsewhere or does IgnoreLayerCollision() not work with IgnoreCollision()? Is there no good alternative?
Your answer
Follow this Question
Related Questions
Bumper physics not working, 1 Answer
Default Contact Offset Problems 1 Answer
2D Ragdoll running game (Ragdoll Runners esk) 0 Answers
RotateAround using physics 1 Answer