- Home /
How come people prefer to use rays for 2d collision instead of edge colliders?
I'm making a 2d platformer and I want to know at any given time which part of the player made a collision with an object. Was it the top of the player? The bottom? The left side? The right side? Originally, I had one capsule collider surrounding the player, but I had no idea how to detect which side of the capsule collided with another object. So I replaced the capsule with 4 different edge colliders, one on each side. This seems to work, but it's not the way that everyone else does it. Everyone else uses raycasting to detect which part of the player collided with an object. For example, they'll have two or three rays coming out of each side of the player to detect collisions. Why do they do this instead of using an edge collider for each side? Also, does anyone know if it's possible to still use my original capsule collider to detect which part of the player collided with what?
Because Raycasting is the way to detect on which part the sprite was hit. If you want to use edge colliders, use multiple to detect where the sprite was hit, but that can be taxing. See: https://answers.unity.com/questions/393773/capsulecollider-how-to-get-the-info-which-part-is.html
Answer by Nishchhal · Nov 26, 2017 at 10:33 AM
Because the collision in Unity is still buggy, so people prefer to use raycast to detect things around the player, using raycast will give you much more flexibility in terms of overall game performance and customisability.
Your answer
Follow this Question
Related Questions
Gameobject not detecting collison from other Box Collider 2D [SOLVED?] 2 Answers
RaycastHit2D hits the objects from start point of Raycast 0 Answers
2D - Two objects, each having two trigger colliders - interacting 0 Answers
Problem with method Collider2D.isTouchingLayers() 4 Answers
CircleCast hits emitter with Collider2D 0 Answers