Body made of rigid bodies

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

Hi,

I am currently trying to build a robocraft-like game (is about building a vehicle using cubes, weapons, wheels, thrusters… ) and I got incredibly stuck.

Let me explain:

I have a scene “cube”, with a script attached that controls health and other events.
The cube root node is a rigid body with a box collision shape and a meshinstance loaded from a .obj

Now I define a main scene with a spatial node called “Vehicle”, which has two childs:

  • a spatial “orbital_camera” node for a camera that orbits the vehicle (works ok)
  • a spatial node called “VehicleBody” which holds all the vehicle geometry.

The scene also has a static body called “Map”, that consists in a flattened box acting as ground.

Question A:
If I instance some “cube” scenes as child of VehicleBody, they physically behave like completely separated objects, despite being on the same node. What am I missing here?

Question B:
If I change the node type of “VehicleBody” to rigid body, cubes seem to be locked in place between each other (good thing), but they will not collide with anything (bad thing) or interact physically. I understand that this is due to their global position being attached to a rigid body without collision shape?

Question C:
If I change de node type of “VehicleBody” to rigid body, and by gdscript I attach the collision mesh and visual mesh, it collides and cubes stay together. But then I lose the capability for each cube tracking their own things without any other external control. Also, they have no weight and the vehicle moves weird. This implementation could work by applying a gravity force on each cube at every physics step, checking the state of every cube in a global list, handling block removal by the parent node… I find this way of proceeding nonsensical and perfomance killing in comparison with the idea of scene instancing and keeping everything as loosely tied as possible. Is this the only way possible?

After reading all the painfully sparse documentation, examples, qa and everything, I think I am missing something big here, but I just can’t figure out.

Thank you.
Javier.

:bust_in_silhouette: Reply From: VonMoustachen

Some news:

Partially solved this, seems working so far. I can define a set of blocks with some functionality and spawn them with their individual collision meshes. The downside is that I have to manually recreate gravity and inertia tensors (g was easy, inertial left for later). Now I am crawling to get steering wheels to work properly.

This video shows my first constraint-based approach (not the current implementation, will post in the future if it works):

Also, this is a similar unanswered question:
https://forum.godotengine.org/28594/rigid-compound-body-consisting-multiple-physical-properties?show=28594#q28594