A playground for developing a semi-realistic vehicle simulation for games in the Godot Engine. The goal of the project is to develop vehicles that behave as close as possible to real vehicles while keeping the code as simple and fast as possible. Vehicles are to be made up of different configurable building blocks to allow the creation of various types of vehicles, e.g. FWD/RWD/AWD combustion engine/electric cars, trucks, trailers, trikes, bikes, etc.
Vehicles are created from a set of nodes and resources.
In general, the nodes are supposed to connect the various components, while the resources are supposed to be independent, so as to be potentially reusable in multiple contexts.
For example, Axle
depends on Wheel
, but Transmission
does not depend on Motor
or any of the other components.
Vehicle
Axle
RigidBody3D
and requires collision shape(s), realistic mass and center of massMotor
to drive the vehicleTransmission
to support multiple gearsDifferential
to split torque between front and rear axle
Axle
Vehicle
and contain at least one Wheel
Differential
to split torque between left and right wheel
AntiRollBar
to reduce vehicle rollWheel
Axle
Tire
for determining traction forcesSuspension
for independent wheel suspension
Brake
for braking and traction controlAxle
and Wheel
could also be used outside of the intended hierarchy, but would require manual handling that is normally provided by their intended parent node.
Note that some resources are stateless and single instances can be reused while others are stateful cannot be reused.
Resources that would commonly be reused tend to be stateless, including Tire
, Suspension
and Brake
.
Here, state refers to dynamic input at runtime, e.g. current suspension compression, rather than properties that are considered static configuration, e.g. suspension stiffness.
Configuration parameters can still be changed at runtime and will affect all dependents, e.g. all wheels using a common suspension resource.
Motor
(stateful)
Transmission
(stateful)
Differential
(stateful)
AntiRollBar
(stateful)
Tire
(stateless)
Suspension
(stateless)
Brake
(stateless)
A typical four-wheeled car should have the following the structure.
Vehicle (Motor, Transmission, Differential)
├ Collision Shapes
├ Meshes
├ Axle (Differential, AntiRollBar)
│ ├ Wheel (Tire, Suspension, Brake)
│ │ └ Mesh
│ └ Wheel (Tire, Suspension, Brake)
│ └ Mesh
└ Axle (Differential, AntiRollBar)
├ Wheel (Tire, Suspension, Brake)
│ └ Mesh
└ Wheel (Tire, Suspension, Brake)
└ Mesh
For concrete examples see the /vehicles directory.
See Project Settings > Input Map
for all input mappings, but here is a short summary.
Note that holding brake does not automatically reverse. You need to manually shift into reverse and then accelerate as usual. Shifting is possible even if the transmission is automated, but gear changes between forward gears will quickly be overriden by the automation algorithm.
This is a result of the ray/shape-cast approach used to simulate the wheels. They do not have their own collision shapes and cannot be handled by the physics engine. All interactions with the environment, such as the traction forces, must be coded manually. While wheel collisions could be handled to a certain degree, doing so is difficult and might not even make a big difference in some cases. For now, it's out of the scope of this project.
The automation algorithm for the transmission was hacked together quickly, just to have some kind of automatic transmission for easier testing. It attempts to always select the gear that will provide optimal acceleration. Unfortunately, sometimes it will shift to unnecessarily high gears. I have not looked into the issue, since it's quite low-priority for me.
Unfortunately, I have not yet looked into the issue yet, but I suspect it might be a case of the engine immediately hitting the RPM limit, cutting off, hitting the limit, cutting off... you get the point. There shouldn't be a problem with realistic torque values. The example vehicle with a real-life engine peak torque of 700 Nm seems to work properly even with a peak torque of 2700 Nm.
A clutch is currently not being simulated. The engine is either fully engaged or fully disengaged from the drivetrain at any point in time. In addition, the simulated engine RPM are artificially restricted to not fall below the defined idle RPM, even if the wheel RPM are lower. Overall, this acts like a clutch when accelerating from a standstill, but is not physically correct. As a side-effect, the engine cannot be stalled.
Yes, there is no ABS yet.
The provided example vehicle uses the following third-party assets.
Specs for the example vehicle have been retrieved from the following sources.