Get/set center of mass

I was looking for a way to find a center of mass for a static mesh. Right now I’ve build a simple simulation for airplane wing. Being able to set or at least to know current center of mass would save hours of debugging.
Applications of this feature can be quite varied, some of them can’t even be done without it. For example if you want to have assisted control for a spaceship or aircraft, which are driven by physics. Then we have to know center of mass so that torque can be calculated before the force is applied.
Is there a way to do it at least from c++? If yes I could find myself how to expose is it blueprints.

And now I’m really stuck because I can’t get proper torque forces. Even if apply all forces with just AddForce I need to calculate torque myself and for this I need … Center of mass

Another unfortunate side of this issue is that calculated center of mass is off from the model origin in all three axis. Model is symmetrical along X axis but I can clearly see that even if forces are applied along Y axis there is small torque starts to creep and puts simulation out of balance.

So it’s time to start working of flight assist but for that I need to know center of mass.

maybe make a blueprint of the actor class, add the static mesh in the components tab, and then add a blank sphere component in the center as your target and link everything to that?

I’ve tried that and it does improve stability of torque calculation. Unfortunately main body of the airplane is going to be a skeletal mesh, so I can have a collision, landing gear with simple wheels and etc. But then the center of mass will be in where ever algorithm which calculates it decides.
I don’t know how I can combine sphere and skeletal mesh in such a way that it would actually work. As of now, calculated center of mass, can be in so bizarre place that my physical wings have to be really of from the model wings.

Attaching illustration, red sphere is approximate location of the center of mass. I don’t know how it’s calculated, but for body with a uniform density, center of mass should coincide with center of volume, which doesn’t look to me to be a case.

Have you asked about this in C++ section of the forums? I’m curious about how it can be found and if it works at all. I ran into this issue with thrusters a while back and then gave up on thruster component and physics driven flying objects.

Hi Jacky, I’ve seen your post. Sad to hear that you had to abandon your idea. Good idea about asking this in C++ section of forum, will do that right now.
Cheers

I see two workarounds so far:

  1. Place a sphere or cube mesh as root component in actor’s hierarchy. Place rest of the objects as it’s children so they will be attached.

Pros: It works and allows to shift center of mass if needed by offsetting it in the root, which is now always located at the actor’s origin.

Cons: I’ve experienced significant difference in stability between sphere component (available by default as actor component, used for bounds and etc.) and custom cube imported from external application. Somehow the shape or a size of the objects influences stability. The mass was suppose to be the same and was simply scaled with parameter. Collision has to be processed by a child mesh, so far I didn’t figure out the recipe of how it can be done.

  1. Triangulate center of mass using several AddForceInLocation forces and resulting angular velocity.

Pros: should work with any mesh as a root body.

Cons: Precision can be an issue. Triangulation should be done without any kind of velocity dumping on body but simulation would most likely need it. Have zero idea how to do it in constructor as physics simulation most likely won’t be running there.

Non of these are the proper solutions in long run. Ability to set/get center of mass, which is I believe just one of the properties of PhysiX object, should be the proper way to handle this. I’m not an expert in physics simulation and might be completely wrong here. Response from developers on this matter is greatly appreciated.

Hi all,

The center of mass is not really exposed right now, but I agree we should as this would be really useful. I’d like to get this in for 4.6 if possible!

A possible workaround is to look at FBodyInstance which has a function called GetPxRigidDynamic() which will return a PxRigidBody. Once you have this you can query the center of mass by calling getCMassLocalPose which will return a PxTransform. We have utility functions like P2UTransform which will convert this PxTransform into an FTransform so that you can use it with the rest of unreal math library.

This is not ideal but if you’re really blocked it’s worth taking a look. If you’re doing this and run into any issues please let me know and I’ll try to help you out. Thanks for bringing this up

Thank you, Ori!
Maybe I’ll try to add this as a plugin before it get’s official update.
What P2UTransform does?

Awesome! Hope it makes it to 4.6. Thanks, Ori. :slight_smile:

P2UTransform takes a PxTransform (transform representation in PhysX) and converts it to an FTransform (transform representation in unreal).

So I too need to get this now (glad to see its on the radar for 4.6), I assume it will/can be exposed to Blueprints too? Also, how will it work with Welded meshes?, can I get the COM form the parent object and it will return the COM of the whole welded mesh? because that would be AWESOME!

I just submitted a change that lets you get the center of mass from blueprint. In the case of a welded body it will give you the center of mass of the entire welded object. It should be in 4.6, but you can grab it off github now if you’d like:

https://github.com/EpicGames/UnrealEngine/commit/e5c9fb6a9695eb6c3954ccf41d89499d7fc14636

Thank you, Ori!
This is a great news! Now we can use COM’s Offset to set COM into specific place too.