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

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.

collider2d.density * area