To simulate accurate wheel behavior in Unity, you use a Wheel colliderAn invisible shape that is used to handle physical collisions for an object. A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. More info
See in Glossary for each wheel. Wheel collidersA special collider for grounded vehicles. It has built-in collision detection, wheel physics, and a slip-based tire friction model. It can be used for objects other than wheels, but it is specifically designed for vehicles with wheels. More info
See in Glossary manage wheel rotation and vehicle movement, and also have properties that simulate a suspension system.
The Wheel collider component is represented in the API as the WheelCollider
class.
The Wheel collider appears in the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary view as a 2D circle (see Wheel collider visualization). However, it is actually a single Physics raycast. PhysX casts the ray down the local Y-axis along the direction of suspension through the center of the wheel. The start and end of the raycast are at the following points:
This raycast configuration means that a Wheel collider does not actually roll across other surfaces (such as the ground) while moving. In Play mode, the rotation of the Wheel collider does not change. However, the rotation of the wheel model does need to change so that the wheel appears to roll along the ground. To achieve this, the model and the collider need to be on two separate GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary. The Wheel colliders’ Transform should be fixed relative to the vehicle, and the models should be able to rotate. You can then configure the Wheel collider to send its global position to the wheel model and rotate the wheel model via script. For an example of this workflow, refer to the walkthrough Create an example vehicle with Wheel colliders.
For more details on the Wheel collider raycast setup in PhysX, refer to the PhysX 4.1 Vehicles SDK documentation.
An important implication of the raycast setup is that wheels don’t always smoothly roll up or step down variations in road level (for example, rolling up from the road onto a step). When encountering a step or curb, the wheel is likely to clip and then “pop” up only as the center line crosses the step:
The raycast can also slip down into small drops or steps in the road when the center point reaches them:
For this reason, the ground collisionA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary geometry must be as smooth as possible to ensure a smooth and accurate simulation. If you have bumps or dips in the ground, you must test and iterate on them to make sure you are happy with the wheels’ behavior.
When you select a Wheel collider, the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary displays a gizmoA graphic overlay associated with a GameObject in a Scene, and displayed in the Scene View. Built-in scene tools such as the move tool are Gizmos, and you can create custom Gizmos using textures or scripting. Some Gizmos are only drawn when the GameObject is selected, while other Gizmos are drawn by the Editor regardless of which GameObjects are selected. More info
See in Glossary which provides a visualization of some key Wheel collider properties.
The gizmo’s visual indicators are as follows:
You can use the gizmo visualization for quick reference and debugging.