- Home /
Detect collisons only on the border of a collider,How to detect collisions only on the border of a collider but not inside?
I am creating a 2D game and i want to implement two game objects with circular colliders to detect collisions as follows. Suppose an object is travelling from Point A to Point B then
See the image for details.
Thanks for the help
Answer by dougantor · Mar 21, 2020 at 11:21 PM
Just using OnCollisionEnter2D and OnCollisionExit2D will almost get what you want and is easy to set up. The only problem is that OnCollisionExit2D will only be called once the object has fully left the other object. I would suggest having a second smaller collider and detect when you're also inside that and stop doing whatever it is you're doing when that happens. Also, I haven't done any 2D stuff, but you probably want to use triggers, not colliders (i.e. check the "is trigger" checkbox on the colliders and use OnTrigger[Enter/Exit/Stay]2D)
Your answer
Follow this Question
Related Questions
Problem with collider2D crosses other collider2d 1 Answer
Collider that can perfectly fit the shape of a sprite? 2 Answers
How to optimize a lot of colliders? 1 Answer
2D Physics and Jump-Through Platforms 2 Answers
Unity colliders bug (2d box) 2 Answers