- Home /
How to make rigidbody recalculate center of mass? (Or rather, why is the center of mass outside of my meshcollider)
I'm swapping out a mesh in my meshcollider. Is there any way (not involing straight up removing the current rigidbody and adding a new one cause I have like a milion things depending on it) to recalculate the center of mass and inertia tensor, other than doing it manually?
Not that I can't do it manually, just seems like a stupid thing to do when the functionality is clearly somewhere within the rigidbody component.
UPDATE: Afer some testing I've noticed that it actually DOES recalculate the center of mass when swapping the meshes. However, the center of mass is placed OUTSIDE of the mesh. The mesh is convex. I've no idea what I'm doing wrong. Attaching a picture, the center of mass is marked as the red wiresphere.
UPDATE: A through read of the docs and some poking around revealed what the issue was. According to the docs: Note: centerOfMass is relative to the transform's position and rotation, but will not reflect the transform's scale! https://docs.unity3d.com/ScriptReference/Rigidbody-centerOfMass.html
Because my mesh was scaled roughly 4 times, the center of mass appeared to be outside because I used transform.TransformPoint(GetComponent().centerOfMass) to get its global coordinates.
Answer by HenryStrattonFW · Feb 18, 2018 at 08:47 AM
https://docs.unity3d.com/ScriptReference/Rigidbody.ResetCenterOfMass.html
Docs look like this would be the function to go for.
EDIT: just noticed your update. That is odd, is the mesh collider offset in anyway on the object?
A through read of documentation allowed me to find the issue. Center of mass isn't scaled with the object's transform. Thank you.
Ahh that's interesting to know. Glad it's all sorted now.
Your answer
Follow this Question
Related Questions
centerOfMass and local coordinate origin 1 Answer
How can I rotate around with a Rigidbody while respecting physics? 0 Answers
Calculate forces required to rotate around an arbitrary point regardless of center of mass position 1 Answer
When does Unity calculate center of mass and inertiaTensor? 2 Answers
Non Convex Mesh Colliders even though there aren't any 1 Answer