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.
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.
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.
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?