- Home /
Track all colliding Collider2D.
I want to keep track of all Collider2D what is touching my player.
I used: OnCollosionEnter/Exit2D with a List but it just fails to remove some Colliders.
void OnCollisionEnter2D(Collision2D coll) {
collidingTiles.Add(coll.transform);
}
void OnCollisionExit2D(Collision2D coll) {
collidingTiles.Remove(coll.transform);
}
I saw someone using the intersection of the renderer's bounds, but I think it's not the appropriate way. Is there a solution for this?
Answer by klolololol · Apr 10, 2015 at 12:32 PM
Eventually I used this function to solve the problem in my Player's FixedUpdate method.
Physics2D.OverlapCircleAll(player.transform.position, playerCollider.radius, 1 << LayerMask.NameToLayer("Ignore Raycast"));
Your answer
Follow this Question
Related Questions
OnCollisionStay2D not working in the way I would like. 1 Answer
Maintaining the set of contact points. 1 Answer
OnCollisionEnter/Exit and Collider edges. 1 Answer
C#: How can you make your character jump only when you are touching the top of the object? 2 Answers
Does a collision occur when a collider 2d is enabled on top of another? 0 Answers