Awesome
Godot-6DOF-Vehicle-Demo
Demo using Godot Engine Generic 6DOF joints to make a fully working, physics based vehicle.
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.
Main Features
- 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.
Disadvantages
WARNING: As of February 2022, 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:
https://github.com/godotengine/godot/issues/54761
https://github.com/godotengine/godot/issues/46596
https://github.com/godotengine/godot/issues/50463
https://github.com/godotengine/godot/issues/36729
- 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 February 2022, I've tried to make a 6DOF setup in Godot 4.0 Alpha 1, and the 6DOF ANGULAR MOTOR (that makes the wheels spin), doesn't work, see issue #54761, above.
Future Updates
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.
Other Approaches
Since the idea is to share and spread knowledge, there is no reason for me not to mention other vehicle physics approaches in Godot. Here is just a brief list of things I've found interesting around the internet.
GDSIM by Wolfe
https://www.gtplanet.net/forum/threads/gdsim-v0-3a-launch-sim-workshop-devlog.396400/
https://www.youtube.com/watch?v=aqUTh39nGSM&list=LL&index=10
Godot Engine - Advanced Vehicle Physics by Thales Kruger Games
https://www.youtube.com/watch?v=PZjpnn9Jmow&list=LL&index=9&t=391s
https://sabudum.gumroad.com/l/PsTbK
Tobalation/GDCustomRaycastVehicle
https://github.com/Tobalation/GDCustomRaycastVehicle
Voxel based game by soloCodeNet
https://www.reddit.com/r/godot/comments/oz2358/all_voxel_based_game/
Sphere base physics by KenNL
https://www.reddit.com/r/godot/comments/oyh3vb/ive_been_learning_godot_for_a_week_or_two_now_and/
Simple 3D Car Physics using RigidBody and Raycasts by MikeLumos
https://www.reddit.com/r/godot/comments/la2jxa/simple_3d_car_physics_using_rigidbody_and/
https://godotacademy.gumroad.com/l/godot-racing/free%E2%80%8B
Physics based hoverboard in Godot by MrEliptik
https://github.com/MrEliptik/godot_experiments/tree/master/3D/hoverboard