Change Rigid body's center of mass

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

I am making a 2D game were you can build spaceships with blocks, I have a rigidbody2D as the root node for the spaceship, the best way i could think of is to have all blocks be collision shapes as child of the ship, when placing these blocks they get added to a Dictionary.

my structure looks like this:

  • Node2D (world)
 - RigidBody2D
  • CollisionShape2D (block: 0,0)
  • CollisionShape2D (block: 0,1)
  • etc.

when i play the center of mass of the ship is at the origin of the rigid body so (0,0). is there a way to change the center of mass of the ship, or group all the CollisionShapes under a Node2D or something so I can just move the children and the rigid body so that the center of mass matches?

If you have any other ideas on how to handle this situation than thats good as well.

:bust_in_silhouette: Reply From: sash-rc

RigidBody’s origin is a center of mass.
So yes, move collision shape and visual parts accordingly to achieve desired effect.

You can read more background in this previous question

AndyCampbell | 2020-11-12 00:22

:bust_in_silhouette: Reply From: Merlin1846

Use tile maps instead for the collision, if you turn on use parent then the rigid body will use the tile map for its collision. Also just change the tile maps position to change the rigid bodys center of mass.

-Rigid body
–tile map (with use parent turned on in collision.)

The tile map can even handle graphics, and an array or dictonary can handle the tiles individual hp and other info.