0 votes

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... :(

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

Thank you in advance!

Godot version 3.4.4
in Engine by (80 points)

1 Answer

+1 vote
Best answer

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)
----Pinjoint1
----Wheel1 (Rigidbody)
----Pinjoint2
----Wheel2 (Rigidbody)
----Pinjoint3
----Wheel3 (Rigidbody)
----Pinjoint4
----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 :)

by (177 points)
selected by
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.