The physics and joints setup is exactly the same I use on my racing game TrackMaster: Free-For-All Motorsport.
After 1.5 year of development of TrackMaster, I decided to make a free and open source demo of the basics of how the game vehicles works.
Every time I've posted videos of TrackMaster's updates, I always received questions about how I made the physics, and how I use joints.
Seeing how there is little to no educational resources (tutorials) on 6DOF joints in Godot, I decided it was time to make a small contribution to the Godot community, and this is also a way to say "thank you" to this ever growing and awesome community.
This demo contains:
- A main scene, with obstacles and ramps, as static bodies.
- A working, physics based, monster truck like vehicle, based on 6DOF joints, with the script that make it works.
- The blend file used for the vehicle visual instance (mesh).
- Two additional scenes, with no scripts, showing the very basics of 6DOF joints.
- Works with Godot 3.x.
- Use this demo the way you like it, it's completely free.
- Just press F5 and have fun!
- Completely physics and joints based, no raycast suspension or other methods (not that it's better, it's just a different approach). This means torque is added to the wheels and the spinning of the wheel makes the vehicle move.
- Body and wheels are regular rigid bodies. This has the advantage of the vehicle behaving in a completely free way, with no physical constrains: it can roll, topple and react to any other static or rigid body.
- Eventual moving parts you may want to add, like doors and bumpers, can be added in the same way, with rigid bodies and 6DOF joints.
- The physics behaviour (suspension travel, acceleration, top speed) needs no code. They are all 6DOF joints parameters set in the editor. In the demo, I set acceleration and top speed inside the code for convenience, but it doesn't need to be this way.
- Script is only needed for input, to control the vehicle.
- Inputs are custom actions, defined in the INPUT MAP (PROJECT SETTINGS).
- Physics run on 240 FPS, for stability reasons. Sincerely, in this demo there would be no difference to run with 60 or other physics FPS, but if you want to try bigger tracks/maps/environments, it can be an issue. More on this topic on DISADVANTAGES, below.
WARNING: As of July 2021, this demo only works with Bullet physics.
- The advantage of being completely physics based can also be a disadvantage, depending on what you want to achieve. This setup is subject to suffer from the following bugs/issues:
- Since Bullet will be an official plugin in Godot 4, and the default physics engine will be Godot Physics, you may also think if you want to use a setup like this.
- As of July 2021, I've tried to make a 6DOF setup in Godot 4, and couldn't even assign two bodies to the joint in the editor.
I can't guarantee future updates. That said, I may update this demo in the future. Please, share your opinion, feedback and request for more features.
I also may make a video tutorial in the future, explaining every detail.