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 sakraf · Nov 16, 2016 at 05:23 AM · unity 2drigidbody2dcollider2dmassdensity

How is Rigidbody 2D Auto Mass calculated?

Hey can someone tell me how the mass of a rigidboody is calcuated when use AutoMass is enabled? I know that it is dependant on the Collider size and on the Collider density but what's the exact formula? I was not able to find this in the Docs.

I tried setting the density of a circle collider to 2 and the radius to 2. The mass is now 100.531.

Although 2*2=4 so V * rho = m is not the formula. Can someone help me?

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by MelvMay · Nov 16, 2016 at 08:19 AM

Unity uses Box2D for its 2D physics. Box2D wants to calculate the mass by assigning a collider a density and multiplying that density by the collider's area to give the mass. This is how Box2D works however Unity has historically presented an explicit mass value.

UseAutoMass essentially works how Box2D wants to work i.e. when it is set to true, you can set a density on each collider and the collider's area multipled by this density will give that colliders mass. The Rigidbody2D adds-up the mass for all colliders attached to it and this is the final 'auto mass'.

I would suggest you go to the Box2D source code here: https://github.com/erincatto/Box2D/tree/master/Box2D/Box2D/Collision/Shapes

If you look at each shape's implementation (.cpp file) and look for a function named "ComputeMass()". You'll see it calculate the shape's area and multiply it by its density.

Note that the function name is slightly misleading as it's calculating the 'mass data' which means calculating not only the mass but the rotational inertia and the local center of mass.

Hope this helps.

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

Answer by UNDERHILL · Nov 16, 2016 at 07:02 AM

https://docs.unity3d.com/ScriptReference/Rigidbody2D-useAutoMass.html

collider2d.density * area

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

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

Can I make mass and density constant independent of Collider 2D size? 1 Answer

useAutoMass and child objects 1 Answer

Calculate objects' mass based on density and volume 1 Answer

Why do GameObjects need Rigidbodies to collide? 0 Answers

Can I create boundaries around my level without using box colliders? 3 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