- Home /
Physics2D.OverlapCircleAll and OverlapCapsuleAll behaves differently?
LayerMask Body = LayerMask.GetMask("Body");
float DetectWidth = 5;
float DetectHeight = 4;
colliders = new List<Collider2D>(Physics2D.OverlapCircleAll(transform.position, DetectWidth, MaskLayer.Body));
colliders = new List<Collider2D>(Physics2D.OverlapCapsuleAll(transform.position, new Vector2(DetectWidth, DetectHeight), CapsuleDirection2D.Horizontal, MaskLayer.Body));
I changed a logic of finding nearby colliders from the upper one (Overlap Circle All) to the bottom one (Overlap Capsule All). I assumed the only different would be the area of searching--from the circle one with a radius of DetectWidth to a capsule one with DetectWidth & DetectHeight.
However, Overlap Capsule All seems to ignore layerMask specified in the parameter. A player object has a completely different layerMask so named "PlayerBody" instead of regular "Body" used on enemy colliders, but the player collider is detected only by Overlap Capsule All. But not on Overlap Circle All.
I can't figure out the cause of this issue. I've seen that capsule with size near 0 might cause some layermask detection issue, but I made it certain that the size of capsule big enough (a lot bigger than most of my collider objects). My project really benefits from Overlap Capsule All, so I'd like to use it without such error occurring. Is there any way I can fix this issue?
Your answer
Follow this Question
Related Questions
overlayCircle not working 1 Answer
Physics2D.OverlapBoxNonAlloc not return all overlapped collider 1 Answer
How to Detect if a Collider is in the Area, Move Away, Rinse and Repeat? 1 Answer
Physics2D.OverlapArea inaccurate? 2 Answers
Physics2D.OverlapBoxAll and Physics2D.OverlapAreaAll are inaccurate. 0 Answers