Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Mikker · Aug 18, 2014 at 12:17 AM · 2dcollisionphysics2d

Physics2D.OverlapAreaAll/NoAlloc fails detecting object in puzzling manner

I have an issue with a 2D collision that fails to detect an object.

I am working on a 2D platformer, with sprite objects using box colliders. The main character has several scripts that controls his behavior; one for maintaining positions for collision purposes as Vector2Ds (like bottom, center, and right) and one for the main movement and collision detection. In order to detect an object, in this case a ladder, I use OverlapAreaNoAlloc with the characters position, detecting objects on a custom layer (512). The same issue is present with OverlapAreaAll. The ladders all have non-trigger box colliders.

However, in the test room I have made, the player fails to detect ladders with an x-coordinate between ~4.1 and ~8.2. Ladders before this and after that position works. The object itself does not matter - different objects behave identically, and moving one in and out of this zone, even at runtime, changes its behavior.

What is most puzzling is that I have isolated the problem to the origin of the float coordinates used. If I use the coordinates obtained through a reference to the other script, it fails, while if I base the coordinates on the transform.position, it finds the ladder. The only line of code (as well as a debug log) I change is the one below:

(fails)

int count = Physics2D.OverlapAreaNonAlloc(new Vector2(cols.VBack3.x, cols.VCenter.y), new Vector2(cols.VFront3.x, cols.VUp.y), ladders, ladderLayer);

Debug.Log("checking cords: (" + cols.VBack3.x + "," + cols.VCenter.y + "), (" + cols.VFront3.x + "," + cols.VUp.y + "), " + count);

(succeeds)

int count = Physics2D.OverlapAreaNonAlloc(new Vector2(transform.position.x - cols.Dist_Hor + 0.03f, transform.position.y), new Vector2(transform.position.x + cols.Dist_Hor - 0.03f, transform.position.y + cols.Dist_Vert), ladders, ladderLayer);

Debug.Log("checking cords: (" + (transform.position.x - cols.Dist_Hor + 0.03f) + "," + (transform.position.y + 0.13f) + "), (" + (transform.position.x + cols.Dist_Hor - 0.03f) + "," + (transform.position.y + cols.Dist_Vert + 0.13f) + "), " + count);

When positioning the character at roughly the same position (roughly 1 pixel difference), the above two debug logs prints out

checking cords: (7.523224,0.99), (7.573224,1.1), 0

checking cords: (7.531714,0.99), (7.581715,1.1), 1

with the objects to be found having collision at: (7.41,0.72), (7.57,1,68)

In other words, Physics2D.OverlapAreaAll and Physics2D.OverlapAreaNoAlloc magically knows when a number is from another script and stubbernly refuses to work within a particular area of about 400 pixels. For no reason. With a 100% fail rate. I am currently using Unity 4.5.1f3 (free version). Have I missed something completely here or is this a bug in Unity itself?

I'm looking forward to see if someone can clarify this issue.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mikker · Aug 19, 2014 at 09:16 PM

Found the problem. Apparently Physics2D.OverlapArea doesn't work when the area is too small. Making the area larger fixes the problem.

An area of 0.05x0.11 is apparently too small for OverlapArea. This seems like a pretty severe flaw in Unity.

Comment
Add comment · Show 1 · Share
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 briveramelo · Oct 19, 2014 at 05:57 AM 0
Share

I'm having the same issue and noticing the same behavioral outcomes with size. I just switched from 4.3 pro to 4.5 free and started experiencing this problem. Very frustrating.

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

2 People are following this question.

avatar image avatar image

Related Questions

Colliders 2d apparently touch each other even if they should not. 2 Answers

Having problems with 2d collision triggers (javascript) 1 Answer

Colliders in a wall jut out 0 Answers

BoxCast, OverlapArea, and Raycasting; ground detection questions 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 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