写在前面:
大家好我是aliaoyun。欢迎来我博客使用UNITY的WheelCollider车轮系统,该系统自带碰撞检测,和物理摩擦功能,能物理方式实现汽车运行。
祝生活愉快!
2020.05.26
一 ;使用Wheelcollider制作的晒车游戏
1.实现了物理漂移功能。
2.实现了后驱功能,和差速器功能。
3.实现了复杂的操作,简单的效果。
4.地形来之UNITY官网的地形,模型来源本网站。
5.创作来源于UNITY的,了解wheelcollider请移步https://www.gamasutra.com/blogs/VivekTank/20180706/321374/(推荐用网页翻译为中文)。
二 ;好的接下来是代码模块:
1.实现发动机功能
在这里插入代码片
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Axleinfo {
public WheelCollider leftwheelcollider;
public WheelCollider rightwheelcollider;
public GameObject leftwheelmesh;
public GameObject rightwheelmesh;
public bool motor;
public bool steering;
}
1.01实现汽车控制,差速,漂移功能.
在这里插入代码片
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**
* 具有差速效果,油门大小,漂移系统,悬挂系统调制
*
*
*
* */
public class CarssCtrl : MonoBehaviour {
public List<Axleinfo> axleinfos;
public float maxmotorTorque;
public float maxsteeringAngle;
public float brakeTorques;
public float decelerationforce;
private Rigidbody rigidbodys;
private Transform trs;
public Transform leftwheelmesh;
public Transform rightwheelmesh;
private float Distance1 = 0.0f,Distance2 = 0.0f;
private float motor1 = 0.0f,motor2 = 0.0f;
private AudioSource asoure;
// Use this for initialization
public void ApplyLocalPositionToVisuals(Axleinfo axleinfo){
Vector3 position;
Quaternion rotation;//获取四个轮子的位置
axleinfo.leftwheelcollider.GetWorldPose (out position,out rotation);
axleinfo.leftwheelmesh.transform.position = position;
axleinfo.leftwheelmesh.transform.rotation = rotation;
axleinfo.rightwheelcollider.GetWorldPose (out position,out rotation);
axleinfo.rightwheelmesh.transform.position = position;
axleinfo.rightwheelmesh.transform.rotation

本文介绍了如何利用Unity的WheelCollider组件制作具有物理漂移、后驱和差速器功能的赛车游戏。内容涵盖游戏机制实现、代码模块解析以及地形和模型来源。还提供了体验链接和Unity版本信息。

3923

被折叠的 条评论
为什么被折叠?



