Make sure that your model has proper rotation for Unity which is Z axis forward, X axis right and Y axis up. In case your model has different rotation either fix it in modelling software or check out the following guide: https://docs.unity3d.com/Manual/HOWTO-FixZAxisIsUp.html
Rigidbodyto the model.
Colliderto the model. Make sure that the layer of the collider is set to
Physics.IgnoreRaycastor a custom layer. For this example
WheelControllerIgnorewill be used. This step is important later on to prevent wheels from detecting the vehicle as ground.
wheel_front_leftor similar. This will allow the script to auto-find them later.
WheelControllerscript is not attached to the wheel itself, a new
GameObjectneeds to be created.
WheelControllerscript and act as an anchor for suspension which means it needs to be positioned directly above the wheel axle.
MeshFilter, etc.) and drag it upwards to the point where you want the beginning of spring travel to be. Afterwards, you can move this object which will in turn move the wheel position relative to the vehicle.
WheelControllerto object created in previous step.
WheelControllerwill fill in all the necessary fields by itself. To check if the values have been (correctly) filled in check out the next section.
Script will try to set up all the values automatically when added to a
If for some reason this fails check the following fields:
Parent- parent is the
Rigidbodyto which the forces will be applied. Usually the root of the vehicle.
Visual- this is the object that represents the wheel mesh. It will be assigned automatically if the object contains “wheel” or “whl” in its name. If not, assign it manually.
Layer Mask- only ticked layers will be detected by
WheelController. Make sure that
Physics.IgnoreRaycastand all you vehicle's collider layers are unticked.
If your vehicle's colliders have no layer assigned create a new layer, assign it to them and make sure it is unticked under
Layer Mask field. If this step is skipped vehicle will fly into the air as the wheels will detect the vehicle as ground and suspension will become and remain fully compressed.
Radius- adjust the values so that the wheel gizmo corresponds to the size of the wheel mesh.
The rest of the fields do not require manual setup. Your wheel should now be fully functional.
Spring Lengthshould not be shorter than ~0.2 (or
Time.fixedDeltaTime* 10). Using very short spring rates might result in suspension bottoming out when wheel travel in one frame is larger than the total length of the spring. This usually results in vehicle bouncing off the ground instead of suspension absorbing the hit. If you want the vehicle to sit lower do not reduce the spring length but rather consider moving the WheelController object up which will in turn make the wheel move up effectively reducing the ride height.
Maximum Spring Forceon 4 wheeled vehicles is vehicle mass times 10.
Maximum Tire Grip Forceon the rear wheels relative to the front wheels.
Settingstab of VehicleController inspector.
By default the asset is geared towards realism. To achieve arcade-like behavior:
Slip Coefficientand increase
Force Coefficient. This will cause the vehicle to be less prone to slipping and spinning out. Good starting values are 0.3 for slip coefficient and 6 for force coefficient.
Force Coefficientto make vehicle slide less afterwards (for the curve in the image below force coefficient of 12 was used):
Vehicle Sideis auto-detected and it determines which side of the vehicle is on. If it is a motorcycle use
Widthneed to be adjusted manually to fit the wheel model. Turn on gizmos to be able to see wheel gizmo.
Rim Offsetis equal to the distance between the suspension center and the rim center.
Drag Torqueis brake torque that is constantly applied to imitate rolling resistance.
Parentis a parent object to which the forces will be applied. Must have a
Use Rim Collideris true a half-circle mesh collider is generated and placed on the top half of the wheel to prevent that section of the wheel detecting objects as ground which can cause the wheel to jump suddenly. Also prevents side of the wheel from going through objects as the ground detection only happens on the bottom half of the tire thread.
Visualis a model representing the wheel. It needs to have Unity-correct rotation and centered pivot. If the rotation or pivot on the model is wrong it should be fixed either in 3D software (e.g. Blender) or by following the steps in this link. The method from the link can be applied both for rotation and pivot.
Visual Position Offsetand
Visual Rotation Offset.
Visual Rotation Offset's Z-axis can also be used to introduce wheel wobble if the wheel is damaged.
Max Forceis the maximum force the spring will be able to exert when fully compressed.
Max Lengthis the maximum extended spring length. Unlike in Unity's
WheelColliderthere is no target spring position setting as the spring will fully extend (as it should) when in the air. Therefore, the resting length of the spring is not known beforehand. Because of that the best way to position the vehicle to be in its resting position is to enter play mode, let the vehicle settle and then copy over the
Force Curveis an
AnimationCurvewith normalized values on both axes (both 0 to 1). X represents spring compression (0 for relaxed, 1 for compressed) and Y axis represents force. Actual X and Y maximum values are adjusted through
Bump Force- maximum damper force when damper is getting compressed.
Rebound Force- maximum damper force when damper is getting extended.
Curve- damper curve that determines relationship between spring velocity (X-axis, normalized) and force (Y-axis, normalized).
Camber At Topand
Camber At Bottomindicate camber at top and bottom of suspension travel.
Squat- as tire applies force to the ground through friction a torque in the opposite direction gets generated around wheel axle.
Squatfield determines percentage of that torque which gets transferred to the vehicle. 1 (100%) will result in rear end squatting on acceleration while -1 (-100%) will do exactly the opposite. In real world this depends on the suspension setup.
Active Friction Preset- currently active friction preset / curve. Check Friction Preset page for more info.
Slip Coefficient- coefficient by which the slip will be multiplied. Can be used to modify friction behavior without modifying currently active curve.
Force Coefficient- coefficient by which the tire friction force will be multiplied. Roughly equal to
Friction Curve's Pacejka Parameters.
Tire's grip increases with load placed on it. How much depends on the tire but in most tires this grip/load relation is linear until certain point when it starts to level off.
Load Grip Curve imitates that relation where X-axis represents percentage (0 to 1) of
Maximum Tire Load and Y-axis represents percentage (0 to 1) of
Maximum Tire Grip Force. Wheel behavior heavily depends on these values.
When the suspension bottoms out a piece of code run that prevents the wheel from going through the ground. This behaves as a very stiff spring and damper, effectively emulating the rubber bump stops on a real vehicle.
Depenetration Spring- The amount of force applied (coefficient) in proportion to the penetration depth. Behaves similar to the normal suspension spring.
Depenetration Damper- The amount of force applied (coefficient) in proportion to the wheel velocity. Reduces the amount of bounce-back on impact. Similar to the regular suspension damper.
Ground detection in WheelController happens by firing one or multiple
Raycasts and working out from those the shape of the terrain. This is heavily optimized and raycasts are batched. Still, number of rays does affect performance as there is some post-processing of received hit data required.
Longitudinal Scan Resolutionand
Lateral Scan Resolutiondetermine the resolution of the grid of rays that will be cast.
Apply Force To Others- if true wheel will interact with other Rigidbodies.
Raycast is used to detect ground the wheel will also detect other objects, such as the vehicle itself. To prevent this a
Layer Mask is used. By default
Auto Setup Layer Mask is ticked and all the layers assigned to the
Parents (Vehicle's) colliders will be automatically removed from the
Layer Mask (i.e. will be ignored).
Layer Maskmanually it is important to also un-tick
Defaultas body collider layer.
Debug sections shows the most important values of the wheel.
Debugto show more detailed debug gizmos.
Suspension Force Magnitudevalue can be used to balance the vehicle's weight distribution. Adjust Rigidbody's center of mass until all wheels have the same force magnitude on the flat surface to get 50/50 weight distribution. If using WheelController asset adjusting center of mass is done through an included script, if using NWH Vehicle Physics 2 this is done through Settings tab of
Rigidbodymass is 1.
WheelControlleris most likely colliding with it's parent vehicle's colliders.
Time.fixedDeltaTimeis too high. Values higher than default 0.02 are not recommended, while 0.1667 (60Hz physics update) will greatly increase the smoothness of the physics at a small performance cost and is recommended.
CenterOfMassscript. High center of mass has the effect of trying to balance a pole on the tip of your finger and is more prone to oscillation.
Friction Curveor too large