The use of WheelCollider components in Unity

For basic usage, please refer to the official Chinese document WheelCollider .
Let's add the points and pits I used in my own development.

The sliding inertia of the car:
increaseWheelCollider.wheelDampingRate

Car grip adjustment:
Forward Friction-> Stiffness (longitudinal, wheel forward and backward)
Sideways Friction-> Stiffness (horizontal, drift)

The car goes uphill and slides down:
1. Forward (Z) to increase the uphill WheelCollider.forwardFriction.asymptoteValue,
reverse (-Z) to increase the uphill WheelCollider.forwardFriction.extremumValue
2. Reduce the mass of the body and increase the mass of the wheels
3. ReadjustWheelCollider.forwardFriction.asymptoteSlip

Note that the wheel orientation of the component cannot be changed manually, its orientation is the same as the orientation of the parent object WheelColliderwith the component.Rigidbody

The problem of easy rollover
is the solution that I think of at present is to see the inspiration of the tumbler, and the rigid center of gravity of the body can be lowered to reduce the situation of easy rollover.
The code to modify the center of gravity is as follows:

using UnityEngine;

public class ChangeCenterOfMass : MonoBehaviour
{
    
    
    public Transform center;
    private Rigidbody r;
    
    void Start()
    {
    
    
        r = GetComponent<Rigidbody>();
    }
    
    void Update()
    {
    
    
        r.centerOfMass = center.localPosition;
    }
}

Create an empty object under the node of the car to set the center of gravity position, pay attention to the assignment localPosition.

Self-made demo screenshots
insert image description here
Related blogs about WheelCollider

Guess you like

Origin blog.csdn.net/qq_39162826/article/details/120305137