Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Gordyus · Apr 06, 2017 at 07:28 PM · rigidbody2dphysics2dboxcollider2d

BoxCollider2D + Edge radius + use auto mass

Hi

In Unity 5.6, we can now add an edge radius to the BoxCollider2D, the performance on my mobile is similar with or without the edge radius and this is exactly what I need for my game. So now I want it ! ;)

To respect the shape, I need to reduce the size of the default box collider.

The problem is when the Rigidbody2D has "use auto mass" to true, it does not consider the collider with radius.

See in picture : alt text

According to the documentation for the edge radius "Controls a radius around edges, so that vertices are circular. This results in a larger Collider 2D with rounded convex corners." So I expected that the Rigidbody use the larger box collider to calculate the mass.

So my questions are:

  1. Is that the expected behaviour ? Or the Unity's team has forget something about this feature and I can report a bug.

  2. What is the best workaround to get a mass close to 1 with auto mass + edge radius ? (Im working on a script that disable auto mass and calculate the mass according to the bigger collider)

Thanks for the help !

sans-titre.jpg (20.0 kB)
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
3
Best Answer

Answer by MelvMay · Apr 06, 2017 at 07:38 PM

Documentation is your friend.

https://docs.unity3d.com/ScriptReference/BoxCollider2D-edgeRadius.html

It is important to know that when using Rigidbody2D.useAutoMass, changing the edge radius does not change the calculated Rigidbody2D.mass even though the collision area has changed. The mass is calculated as if the edge radius is zero i.e.not used.

If you absolutely must do this and must use auto-mass then your only option is to reduce the density of the collider although I do not understand why you'd want to use auto-mass then set the mass to 1.

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 Gordyus · Apr 07, 2017 at 06:33 AM 1
Share

You're right, I've missed this point in documentation. In fact, I have a lot of rigidbodies that use the auto mass option but the mass with edge radius change the behavior of my game.

$$anonymous$$y workaround is to use script like that :

 BoxCollider2D bc2D = GetCompent<BoxCollider2D >();
                         if(bc2D.edgeRadius>0f)
                             bc2D.density *= ((bc2D.size.x + bc2D.edgeRadius * 2f) * (bc2D.size.y + bc2D.edgeRadius * 2f)) / (bc2D.size.x * bc2D.size.y);

That change the density, but I get my initial mass back ;)

Thanks a lot for your help !

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why collision2d happend earlier in rigidboy2d? 2 Answers

2D Box Colliders Overlapping On Collision 4 Answers

What's a good way at keeping a ball bounce around inside the scene? 1 Answer

Why does poligon collider 2d restricts movement of box collider? 0 Answers

Ball bounces at different heights when it shouldn't 0 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