How to use RigidBody3D together?

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

Example car racing: I have two cars. If car 1 drives into a wheel of car 2 at a certain speed (I can calculate), this should transform into a rigid body as quickly as possible. That actually works.

However, the car still has 3 more wheels and car body etc. Now I don’t know which parent node I should use or rather how I should handle the whole (car)? Whenever I include kinematic bodies, everything stops… :frowning:

(I’ve already played around with the RigidBody mode, unfortunately without success.)

Thank you in advance!

:bust_in_silhouette: Reply From: BigTuna675

Hi, it would help if you included a picture of your scene tree! But without knowing what that looks like, I’ll try to take a guess as to what you might want to do.

It also depends on how you want to program the motion of the car. Do you want the car to be propelled via the rigidbody interaction of the wheels against the floor? Or do you want the car to be propelled forward via applying a central force to the car in the direction of motion/turning direction? Or maybe you want the body of the car to be a kinematic body, moving with move and slide or move and collide, and the rigidbody wheels are simply pinned on to the car via pinjoints?

I haven’t made a car in Godot before, but I have ran into issues with childing rigidbodies to kinematic bodies before, because for example if the parent is the kinematic body moving with move and slide, the rigidbody children are kind of being pulled along for the ride, and I don’t think the physics engine likes that.

So here’s one possible solution:
–ParentCarNode (Spatial)
----CarBody (KinematicBody)(Moves with move and slide)
----Wheel1 (Rigidbody)
----Wheel2 (Rigidbody)
----Wheel3 (Rigidbody)
----Wheel4 (Rigidbody)

I imagine the car could either be a rigidbody moving with forces or a kinematic body moving with move and slide. Depends on your larger goals I guess.

Use the pinjoints to pin the wheels where they should be on the car in the editor. you can also dynamically break the joints during runtime if you want to have a wheel explode off, for example.

This has some pros and cons. The parent spatial node won’t move in relation with the rest of the car (con), and that may or may not matter. As long as you remember that the kinematic car is position you’re interested if you have signals coming in/out from other nodes.
The rigidbody wheels and kinematic body carbody are siblings, so they won’t be parented/moved automatically against the physics engine’s wishes, since the pinjoints are accomplishing that for you.

There is also a really handy property of the pinjoint that lets you disable the two pinned nodes from colliding with each other. I imagine this will be helpful to stop the wheels from colliding with the car they’re attached to.

I haven’t tested this for a car like I said, but I was able to make a hanging chain light in a similar fashion to this (pinning multiple rigidbodies together via pinjoints) and it works pretty well.

Good luck! I hope I haven’t led you down the wrong path :slight_smile: