- Home /
The question is answered, right answer was accepted
Problem with collision with two colliders simultaneously in Unity 2D
Hi, I'm developing a simple game like this (link text) but in 2D and adding some improvements. I have decided to implement the bounces of the ball manually and everything works properly except one thing, when the ball hits two colliders at the same time it stops. This occurs for example when it hits the ceiling and the wall at the same time. Example: I think a possible solution would be to ignore one of the two collisions, but I don't know how to do it. I hope you can help me fix it. Thank you!
Answer by ray2yar · Dec 28, 2018 at 02:06 AM
I would add code to detect when the ball is touching two different colliders and not moving- get the normals of both contact points and average them, use that to set the new velocity. OR, and this is probably simpler and better- add a small circle collider in each corner to prevent the situation from occuring in the first place.
Thank you, but i have one more question, how could I detect that the ball is touching two different colliders?
Use physics2d.overlapcicleall This gives the colliders within a circle, so if it's length is 2 or more you have a corner situation.
Solved, thank you so much, it works perfectly!