Dynamically add meshes to RigidBody

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Thorsten

Hey guys,

I’d like to dynamically add some simple Meshes (blocks) to a RigidBody. Tried several things and ended up with:

  1. adding a Meshinstance
  2. adding an appropriate CollisionShape

Looks good in the first place, collisions work and it looks correct, BUT it seems that all new elements do not have any weight. So gravity only works on the initial mesh.

Any hints?


Physics/gravity acts on the body, not the meshes. It sounds like maybe you’re not adding the meshes as children of the body? Show your code where you’re doing this.

kidscancode | 2021-05-16 18:39

Hi there,

I just tried in the Editor (added meshes and collision shapes). Only the first shape/mesh added seems to have weight.

However - I’m missing add_shape (Godot 2) as method for RigidBody. How would I have to do it now?

Thorsten | 2021-05-16 20:02

You need to show what you’re doing then. Because again, a mesh can’t have weight. Only the rigid body has physics properties. Meshes should be attached to it to give it visible components.

kidscancode | 2021-05-16 20:17

This is what I tried in the editor (Scene tree), and yes, MeshInstances and CollisionShapes do match :slight_smile:

The RigidBody with all elements falls correctly and the collisions work, a but in the end everything behaves as if only the first box has weight. You can add as many boxes to the side, the body will never fall over. That’s weird, isn’t it?

Thanks for your support. Love your tutorials!

Thorsten | 2021-05-16 21:32

:bust_in_silhouette: Reply From: kidscancode

I see. That’s not weird at all because the rigid body acts as one body. Adding additional meshes and shapes does not change its behavior. You seem to be expecting that the body’s center of mass will move when adding additional shape children, but this is not the case.

The RigidBody’s center of mass is its position. You would need to distribute those collision shapes around the center as desired to change it. For example, here are three rigid bodies with multiple collision shapes. Notice how I’ve placed them relative to the body’s position:

enter image description here

When they fall to the ground, they pivot around their center of mass:

enter image description here

Thanks, that was very enlightening, a perfect illustration. And a little disappointing in terms of what I had in mind. (I wanted to dynamically add blocks (completely stiff) until the whole structure is out of balance.)

Thanks again!

Thorsten | 2021-05-16 22:27