Unity Simple Car

1、需要在Rigid Body下构造轮子,否则在Editor窗口看不到wheel Collider的轮廓
2、需要把车的mess设置大一点1000,否则很容易被轮子给弹出地面
3、轮子的模型和Wheel Collider在Rotation都为0时坐标轴方向一致,否则之后旋转不对
4、轮胎的高度位置需要一致,防止离地或其他原因导致车无法走动
5、只需要给两个轮子添加动力,其他的轮子会跟着旋转
6、轮胎真实的模型旋转和位置需要从whell collider中获取
7、没有设置动力的轮胎只需要设置旋转即可

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Car : MonoBehaviour {
	private WheelCollider Wheel;
	public Transform realWheal;
	public float angle = 10;
	public float motor = 10;
	// Use this for initialization
	void Awake () {
		Wheel = gameObject.GetComponent<WheelCollider>();
	}
	
	// Update is called once per frame
	void FixedUpdate() {
		//方向盘旋转的轮胎角度
		Wheel.steerAngle = angle;
		//正为向前动力,负为向后动力,0为空挡滑行
		Wheel.motorTorque = motor;

		Vector3 pos;
		Quaternion rot;
		Wheel.GetWorldPose(out pos,out rot);
		realWheal.position = pos;
		realWheal.rotation = rot;
	}
}

下载地址:Unity工程

参考:
https://docs.unity3d.com/ScriptReference/WheelCollider.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值