What you need:
- O3DE 23.20.3
- Vehicle Dynamics Gem
- Vehicle model with separated wheels, and (optionally) a steering wheel
Follow these steps to create the model:
Create the main structure of entities. It should look similar to this, depending on structure of mesh entities:
[Vehicle]
├── [Vehicle visual]
│ └── [Vehicle mesh]
├── [Wheel FL]
│ └── [Wheel FL visual]
│ └── [Wheel FL mesh]
├── [Wheel FR]
│ └── [Wheel FR visual]
│ └── [Wheel FR mesh]
├── [Wheel RL]
│ └── [Wheel RL visual]
│ └── [Wheel RL mesh]
├── [Wheel RR]
│ └── [Wheel RR visual]
│ └── [Wheel RR mesh]
├── [Steering wheel]
│ └── [Steering wheel visual]
In this structure, meshes are located in separate entities, which are children of the visual entities. This is not mandatory but will be helpful if you need to adjust the position, rotation, or scale of the meshes. You can also use multiple mesh entities at the same level. This might the the best option if your model is split into more parts, e.g. if the wheel consists of a rim and a tire.
Add visualization meshes to each mesh
entity (create multiple mesh entities if needed). Add proper transformation.
Follow these rules:
Vehicle visual
must be oriented with the X-axis pointing in the vehicle's forward direction and the Z-axis pointing up. The entity's origin should be located at the vehicle's center, on the ground plane. TheVehicle mesh
must be transformed to match these rules.- The
Wheel
entities must be placed on the top of the suspension - they represent the mounting point where the spring and dumper are attached to the chassis. The relative (to the parent entity) rotation must be zero, and the scale must be 1. - The
Wheel visual
entities must be oriented so that the Y-axis is the rotation axis. To make it simple, set the relative rotation to 0. - The
Wheel visual
entity's origin must be in the center of the wheel to ensure correct rotation. Transform theWheel mesh
to match the requirements from this and the previous point. The position of theWheel visual
entity is not important, as it is adjusted automatically. Move it to the location where the wheel should be placed for convenience. - The
Steering wheel
entity must be oriented so that the Y-axis is the axis of rotation. The origin of this entity must be on the rotation axis.
Origin and orientation of the Vehicle
entity:
Origin and orientation of the Wheel FR
entity:
Origin and orientation of the Wheel FR visual
entity:
Add Wheel Controller
component for each wheel entity. Set the parameters as follows:
- Set
Wheel radius
to match the radius of the wheel. - Set
Spring rest length
to the distance from the top of the suspension to the center of the wheel. Typically this can be adjusted to match the visual model. - Set
Spring travel
according to your needs. This is the maximum distance the wheel can travel up and down. - Set
Wheel visual entity
to the entity containing visual.
The wheel component provides a convenient debug visualization, which can help setting these parameters.
The rest of component's parameters should be set experimentally. In the case of a typical sport car, you can use following values as a starting point:
In the Vehicle
entity:
- Add
PhysX Dynamic Rigid Body
:- The rigid body should have mass and inertia matching the real vehicle.
- Increase
Linear damping
to around0.12
. This will reflect air drag, rolling resistance, and other damping forces. Tune it according to your needs. - To increase vehicle stability keep the center of mass low.
- Add colliders. They should not cover
Wheel
entities and the ray-cast line directed to the ground. Use simple shapes like boxes or capsules if you don't have proper meshes.
Add Vehicle Controller
component to the Vehicle
entity:
- Add
Wheel
entities to theWheels
array. Remember to maintain the order of the wheels from left to right. - Set the
Wheelbase
andTrack
parameters to match your model. - Set other parameters according to your needs.
- Turn on
Manual control
if you want to control the vehicle manually. - Set
Steering wheel entity
if you have the steering wheel visualization.
The component should look similar to this:
The model is ready. You can now test it in the game mode.
Each wheel can be configured with a specific collision group. This will change the definition of the ground on which the wheel drives. By default the All
group is selected, meaning that the wheel will drive on all objects. This can be used to define surfaces on which the vehicle can drive. See the O3DE Collision layers and O3DE Collision groups documentation for more information.
Example (setting the wheels to drive only on the Ground
layer):
- In O3DE select the
Tools
menu, thenPhysX Configuration
. - Select the
Collision Filtering
tab, and in theLayers
menu add a new layer namedGround
. - In the
Groups
menu add a new group namedGround
. - Uncheck the
Default
layer for theGround
group and keep theGround
layer checked. - Select the ground entity and in the
PhysX Collider
component set theCollision Layer
toGround
. - In the
Wheel Controller
component set theCollision Group
toGround
for all wheels. - Now the vehicle will only drive on the ground entity.