engine
engine copied to clipboard
Be able to change the center of mass for compound rigidbody created in editor
Description
Compound dynamic bodies created in the editor are behaving very oddly. Even if there is only one child and that child is setup the same way as a regular primitive rigidbody, the behavior it very different. The way they are interacting with other bodies and the way the editor displays the bounding box of the compound bodies incorrectly makes me believe it's a scaling issue for the children collisions, but I'm not sure.
Here is a sample project for build from master and last major version, both have the same issue: 1.27.0 and 1.28.0
The falling chair demo uses compound dynamic rigidbodies but they're created programmatically, which is what makes me think it is something specific to the editor.
Steps to Reproduce
- Create new project
- Create a dynamic rigidbody in the editor and something for it to interact with (floor)
I created a Editor version of compound physics demo if you want to see if there's a difference in set up: https://developer.playcanvas.com/en/tutorials/compound-physics-shapes/
Oh interesting, looking into that now.
Okay so seeing that work made me think maybe something in the project got messed up along the way so I cloned the chair project and tried to get the chair to behave incorrectly but could not. However it looks like if you specifically do the following you'll end up with the problem.
- Create a new entity from the root
- Add a compound collision and dynamic rigidbody to it
- Create a child with a box collision and a model
- Move the compound parent around using the editor arrows
- Change the child's position
- The editor's bounding box when clicking on the parent should look incorrect and the body will now not interact correctly. You might have to repeat 4-5 a couple times to get that to happen.
Here is the fork of the chairs project with the above.
Ah, I see. Looks like if the children are off centre to the parent, the issue is much more clear.

Centre of gravity for compound collision shape is the origin of that entity. While with primitive shapes, it is calculated based on that primitive bounds. We will be introducing ability to automatically calculate centre of collision compound shape, as well as ability to use set origin (as is now).
Sorry, fat fingered the scrolling on mobile :sweat_smile:
That makes sense and explains the behaviour as when it collides, it's trying to pivot around its centre of gravity.
I'm also running into this problem. It would be nice if this can be fixed, as this issue was created already two years ago.
Looking back on the ticket, it looks like designed behaviour as the pivot/center of mass is where the parent/compound rigidbody is.
What is the issue you are running into @albertvanveen ?
The issue is basically that I expect that the center of the mass is the in the middle of all collision components when I use a compound collider. So if I use only one collision component, I expect that the center of the mass is in the middle of that collision component.
Ah I see. It's unlikely that would change that as it was designed into the way that the parent would be the 'center' of mass where everything pivots around.
For your info:
This is a default way of setting a center of mass in Bullet physics (Ammo)- one would offset the child of a compound body. This should not change, as this is often used in Ammo's raycast vehicles, where you want to make the center of mass below the vehicle body for stability.
In contrast, Rapier physics engine allows an explicit setting for the local coordinates of the center of mass. Otherwise, it automatically detects the center, though, so shifting a child there would not work the same way it would in Ammo, e.g. having a single child in a compound body would always have the centers of the parent body and the child match.
The complexity of auto-setting centre of mass for compounds, would be based on density and volume of reach individual compound shape. Currently it is not that detailed. So developer is left with manual option to define the center.