- Home /
Question by
Retrocy · Nov 16, 2018 at 09:18 PM ·
rigidbody2dcollider2dcollision2d
Fixing an inconsistent 2D collision
Greetings, I'm working on a 2D game that must involve multiple trigger colliders on top of each other (from layer 1) colliding with multiple trigger colliders on top of eachother (from layer 2).
In each collider I have this script:
void OnTriggerEnter2D(Collider2D other)
{
Destroy(gameObject);
}
The behaviour that I want to make is that, when collision happens, for every destroyed gameObject from layer 1, one gameObject from layer 2 gets destroyed. Example: Say the group 1 of colliders consists of 34 gameObjects and group 2 of 20, I want the end result of the collision to be 34-20=14 gameObjects from group 1. But using the script above yields very inconsistent results.
Any ideas on how to go about implementing this behaviour?
Comment