The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+3 votes

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.

in Engine by (27 points)

2 Answers

+1 vote

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

by (1,646 points)

You can read more background in this previous question

0 votes

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.

by (663 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.