Model:GetCenterOfMass()

As a roblox developer I currently have to get every part, find it’s mass & position, then add them up & average the values up together to get the center of mass for an object.

I think it would be intuitive to just have an API for this. It could be called on a Model and would return a Vector3 & a number. The Vector3 value would be the Center of Mass, the number following it would be the total mass of the object.

19 Likes

This would be great.


I’d like to note that BasePart.CenterOfMass still isn’t turned on.

image

If this is implemented then I imagine whatever was breaking BasePart.CenterOfMass will be fixed, and it can be turned on.

The problem with this is Models don’t always (and often don’t) correspond 1:1 to rigid bodies.

A weld or any rigid joint in Roblox makes those two Parts both part of the same rigid body. The center of mass for a rigid body would make sense, but a Model can be composed of multiple rigid bodies, or even welded to Parts outside of the model, which would those Parts part of the same rigid body, even though they’re not part of the Model.

So what do you want the center of mass of?

  • The rigid body of the primary part? Not comprehensive. Includes outsiders. Confusing.
  • All rigid bodies of Parts in the model? Includes outsiders. Confusing.
  • The Model’s Parts only? Doesn’t make any sense if it’s welded to outsiders or has multiple bodies…

Ambiguity is terrible in an API and inevitably gets deprecated. Going through part descendants and summing up and calculating it yourself might be for the best right now?

What’s your use case? Use cases are very important when we’re talking about potentially adding new APIs. Otherwise we don’t know if any potential additions would even address what you want.

I’ll see where BasePart.CenterOfMass is. That would at least let you handle all shape types and meshes correctly. I think there was a minor issue there and someone just forgot about it.

6 Likes

Perhaps calling it on a part? If it’s connected to something then the CoM will return the results of the entire connected mass.

My use case currently is for a building game that’s physics based. I want to show the player where their creation is centered around.

So you specifically want the center of mass for the rigid body a Part is part of, right?

In your case BasePart:GetConnectedParts(true) might help you out a bit. At least you’d know you have the right list of parts.

The documentation is a bit misleading here (which I’ll try to fix), but it will specifically recuse through any rigid joint, including WeldConstraints and Motor6Ds, but excluding any simulated joints. Sounds like what you want.

Try that out. If you find calculating this at all becomes a bottleneck or you have any issues with it let us know.

I’ve suggested exposing rigid body properties somehow before, I’ll try asking about that again.

4 Likes

That’s actually what I’ve been using haha. Thank you for the time to explain it though.

I’m going to take this time to request a method for getting centre of mass of unions and mesh parts again!

The center of the selection box would be the #1 choice for me. Sorry to bump the thread, but I think it’s still necessary. In studio, when there are multiple rigid bodies moving continuously in a model, if the model’s selected the selection box updates in real time. Would this be possible?