engine icon indicating copy to clipboard operation
engine copied to clipboard

Be able to change the center of mass for compound rigidbody created in editor

Open maxbbb opened this issue 5 years ago • 12 comments
trafficstars

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

  1. Create new project
  2. Create a dynamic rigidbody in the editor and something for it to interact with (floor)

maxbbb avatar May 20 '20 20:05 maxbbb

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/

yaustar avatar May 20 '20 20:05 yaustar

Oh interesting, looking into that now.

maxbbb avatar May 20 '20 21:05 maxbbb

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.

  1. Create a new entity from the root
  2. Add a compound collision and dynamic rigidbody to it
  3. Create a child with a box collision and a model
  4. Move the compound parent around using the editor arrows
  5. Change the child's position
  6. 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.

maxbbb avatar May 20 '20 21:05 maxbbb

Ah, I see. Looks like if the children are off centre to the parent, the issue is much more clear. image

yaustar avatar May 20 '20 22:05 yaustar

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

Maksims avatar May 21 '20 13:05 Maksims

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.

yaustar avatar May 21 '20 13:05 yaustar

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.

albertvanveen avatar Sep 05 '22 12:09 albertvanveen

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 ?

yaustar avatar Sep 05 '22 13:09 yaustar

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.

albertvanveen avatar Sep 05 '22 13:09 albertvanveen

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.

yaustar avatar Sep 05 '22 13:09 yaustar

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.

LeXXik avatar Sep 05 '22 16:09 LeXXik

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.

Maksims avatar Sep 06 '22 09:09 Maksims