- Home /
Two Collision 2D
I have two Colliders in my player (Box Collider 2D and CircleColllider2D). I wish to only be able to hit only one object that has a trigger set up. Since I have 2, the output from this code will always be 2 :(. Is there a way to only trigger my circle collider however the box collider wouldn't be triggered? (Output would be + 1 instead of +2).
Answer by theLameBrain · Oct 08, 2020 at 03:03 PM
If the Colliders do not overlap, maybe you could put them each on an empty Gameobject, then make the Empty Gameobjects children for your player?
You would have a script on each "holder" object, and check for collisions from there.
Be sure to tag all the objects as the same thing, so you can use Project Settings -> Physics to keep them from colliding on each other, if that is an issue.
Answer by Verilyzed · Oct 08, 2020 at 05:30 PM
You can ignore one collider everytime it hits something like this:
void OnCollisionEnter2D (Collision2D collision) {
Physics2D.IgnoreCollision(yourCollider, collision);
}
Or you could make a variable which is set to true when one of the collider triggers, then check it if the other one would trigger.
Your answer
Follow this Question
Related Questions
Why do GameObjects need Rigidbodies to collide? 0 Answers
2D - Two objects, each having two trigger colliders - interacting 0 Answers
Detecting whether or not 2 objects are colliding in update() 2 Answers
How to stop Rigidbody2D from getting stuck on corners? 1 Answer
OnCollision2D never worked 0 Answers