汽车建模
-
制作车身:创建Cube—挂载重力组件,设置重力1000
-
制作车轮:Cylinder—只设置一个碰撞组件:WheelCollider,调整合适大小
-
将车轮复制放置于车身下,成为子物体
脚本编写
暴露车轮碰撞
//前轮
public WheelCollider[] frontWheels;
//后轮
public WheelCollider[] behindwheels;
将车轮复制到暴露的碰撞。
Update里面的方法
注意,方法只写到Update里面
void Update()
{
//获取水平轴,大小为0-1
float horizontal = Input.GetAxis("Horizontal");
//获取垂直轴,大小为0-1
float vertical = Input.GetAxis("Vertical");
//遍历前轮
foreach (var wheel in frontWheels)
{
//最大转弯角度30
wheel.steerAngle = horizontal * 30;
}
//遍历后轮
foreach (var wheel in behindwheels)
{
//最大马力200
wheel.motorTorque = vertical * 200;
}
}