Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by JasonSic · Jun 04, 2018 at 09:34 PM · physics2dcollider2doverlapoverlapping

Physics2D.OverlapBoxAll and Physics2D.OverlapAreaAll are inaccurate.

Open this image in a new tab if it's hard to read the small text.

alt text

Attached to the white square is code that should detect any overlapping rectangles and print the results to the console. In this case, only the red rectangle should be detected since the red rectangle is the only rectangle that overlaps the white square. However, the green rectangle is also considered to be overlapping the white square. Why?

alt text

Upon closer inspection, you can see that the green rectangle is in fact NOT overlapping the white square. Using Physics2D.OverlapAreaAll provides the same results. Am I doing something wrong?

 void Overlap()
 {
     Vector2 point = transform.position;
     Vector2 size = transform.localScale;
     float angle = 0;
 
     Collider2D[] colliderHits = Physics2D.OverlapBoxAll(point, size, angle);
 
     Debug.Log("Point: (" + point.x + ", " + point.y + ")");
     Debug.Log("Size: (" + size.x + ", " + size.y + ")");
 
     for (int i = 0; i < colliderHits.Length; i++)
     {
         Debug.Log("- overlapping " + colliderHits[i].name);
     }
 }

FYI, all 4 of the colored rectangles have a BoxCollider2D (trigger) and a Rigidbody2D (kinematic). Also, if the blue and yellow rectangles were moved slightly closer to, but not quite touching, the white square, they provide results just as the green rectangle does now.

greenfucker.png (9.6 kB)
bugs.png (21.9 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NoDumbQuestion · Jun 05, 2018 at 06:43 AM 0
Share

Check if all transform is on Z axis = 0.

Sometime I make a mistake that copy paste 2D colliders on z axis = 0.01 and 0. 2 of them never collide with each other.

avatar image Horschty · Jun 05, 2018 at 07:31 AM 0
Share

How are you drawing the rectangles? $$anonymous$$aybe the actual bounding box is bigger than the visuals if the visuals have a small invisible border. Try logging position and size of both allegedly overlapping rectangles and see if the numbers check out.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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.OverlapCircleAll and OverlapCapsuleAll behaves differently? 0 Answers

Physics2D.OverlapArea inaccurate? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges