WheelCollider 组件用于描述轮胎的物理特性(比如扭矩、转速等),可附加在赛车游戏的车轮上。

A special collider for vehicle wheels.

Wheel collider is used to model vehicle wheels. It simulates a spring and damper suspension setup, and uses a slip based tire friction model to calculate wheel contact forces.

Wheel's collision detection is performed by casting a ray from center downwards the local y-axis. The wheel has a radius and can extend downwards by suspensionDistance amount.

The wheel is controlled with motorTorque, brakeTorque and steerAngle properties.

Wheel collider computes friction separately from the rest of physics engine, using a slip based friction model. This allows for more realistic behaviour, but makes wheel colliders ignore standard PhysicMaterial settings. Simulation of different road materials is done by changing the forwardFriction and sidewaysFriction based on what material the wheel is hitting. See Also: GetGroundHit and WheelFrictionCurve. ——来自 Scripting API

3 个应用例子

1. 通过扭矩来使车加速

GetComponent<WheelCollider>().motorTorque = Input.GetAxis("Vertical") * 25000 * Time.deltaTime;

2. 通过 steer 来控制汽车转弯

float delta=  Input.GetAxis("Horizontal");
GetComponent<WheelCollider>().steerAngle = 20 * delta;

3. 通过 localRotation 控制汽车转弯

float delta=  Input.GetAxis("Horizontal");
transform.localRotation = Quaternion.Euler(transform.localRotation.x, 30 * delta, 0);