深圳公司网站搭建公司编程工具

当前位置: 首页 > news >正文

深圳公司网站搭建公司,编程工具,郑州网站备案地址,360街景地图怎么看#x1f468;#x1f4bb;个人主页#xff1a;元宇宙-秩沅 #x1f468;#x1f4bb; hallo 欢迎 点赞#x1f44d; 收藏⭐ 留言#x1f4dd; 加关注✅! #x1f468;#x1f4bb; 本文由 秩沅 原创 #x1f468;#x1f4bb; 收录于专栏#xff1a;Uni… 个人主页元宇宙-秩沅 hallo 欢迎 点赞 收藏⭐ 留言 加关注✅! 本文由 秩沅 原创 收录于专栏Unity游戏demo ⭐️Unity3D赛车游戏⭐ 文章目录 ⭐️Unity3D赛车游戏⭐⭐前言⭐⭐常见问题⭐ A车辆模型——绘制发动机马力与转速曲线️添加并绘制AnimationCurve 动画曲线️AnimationCurve .EvaluateAPI B车辆模型——发动机和手动挡位的初步实现️添加发动机相关的属性️更新输入控制脚本增添换挡输入️换挡管理挡位比率 C车辆模型——脚本记录️CarMoveControl️CameraContorl️UIContorl️ InputManager ⭐前言⭐ – ️版本: Unity2021 ️适合人群Unity初学者 ️学习目标3D赛车游戏的基础制作 ️技能掌握 ⭐常见问题⭐ A车辆模型——绘制发动机马力与转速曲线 ️添加并绘制AnimationCurve 动画曲线 shift控制Y轴伸缩ctrl控制x轴伸缩 跑车发动机一般是7百左右我们就按照跑车的最大功率来做 ️AnimationCurve .EvaluateAPI 通过X轴获取Y轴值 B车辆模型——发动机和手动挡位的初步实现 ️添加发动机相关的属性 发动机功率扭矩转速n 知识百科:说到汽车发动机要了解几个参数。排量功率扭矩转速。那么这里和参数之间的关系如何 排量就是发动机气缸排出气体的多少。因此说到排量不管四缸三缸二缸一缸只要大小一样排量就相同。 功率单位时间内做功的多少。那么排量越大单位时间做功就会越多因此排量越大功率也会越大。 扭矩它的单位是N·M所以它是力运动单位距离的结果。它反应的是加速度。扭矩越大加速能力就越强。 转速它是单位时间内齿轮转动的圈数。齿轮转的越快传输给轮胎的转速就越高车子就跑的越快。 关键代码 //汽车引擎发动机相关public void CarEnginePower(){WheelRPM();//将轮轴的转速获取// 扭矩力发动机功率 功率扭矩*转速nmotorflaot -enginePowerCurve.Evaluate(engineRPM) gears[gerrsNurrentNum] * InputManager.InputManagerment.vertical;float velocity 0.0f;//发动机的转速 与 车轮转速 和 挡位比率 成比例engineRPM Mathf.SmoothDamp(engineRPM, 1000 Mathf.Abs(wheelsRPM) * 3.6f * (gears[gerrsNurrentNum]), ref velocity, smoothTime);print(engineRPM);VerticalContorl(); //驱动管理}️更新输入控制脚本增添换挡输入 using System.Collections; using System.Collections.Generic; using UnityEngine; //————————————- //————————————————————————————————————— //________项目:
//
_____功能 输入控制管理器 //_____创建者秩沅____________ //_____________________________________ //————————————- public class InputManager : MonoBehaviour {//单例模式管理static private InputManager inputManagerment;static public InputManager InputManagerment inputManagerment;public float horizontal; //水平方向动力值public float vertical; //垂直方向动力值public bool handbanl; //手刹动力值public bool shiftSpeed; //加速shift键//public float clutch; //离合器public bool addGears; //升档public bool lowGears; //降档void Awake(){inputManagerment this;}void FixedUpdate(){//与Unity中输入管理器的值相互对应horizontal Input.GetAxis(Horizontal);vertical Input.GetAxis(Vertical);handbanl Input.GetAxis(Jump)! 0 ? true :false ; //按下空格键时就是1否则为0shiftSpeed Input.GetKey(KeyCode.LeftShift) ? true : false;//clutch Input.GetKey(KeyCode.LeftShift) ? 0 : Mathf.Lerp(clutch ,1,Time .deltaTime);addGears Input.GetKeyDown(KeyCode.E ) ? true : false;lowGears Input.GetKeyDown(KeyCode.Q ) ? true : false;} } ️换挡管理挡位比率 //换挡管理public void shifterGearsChange(){if(InputManager.InputManagerment .addGears ) //如果按下E键,加挡{if(gerrsNurrentNum gears.Length - 1 )gerrsNurrentNum;}if(InputManager.InputManagerment.lowGears ) //如果按下Q键减档{if (gerrsNurrentNum 0)gerrsNurrentNum–;}}C车辆模型——脚本记录 ️CarMoveControl using System.Collections; using System.Collections.Generic; using UnityEngine; //————————————- //————————————————————————————————————— //___________项目: ______________ //________功能 车轮的运动 //_____创建者_秩沅_____ //_____________________________________ //————————————-//驱动模式的选择 public enum EDriveType {frontDrive, //前轮驱动backDrive, //后轮驱动allDrive //四驱 }public class CarMoveControl : MonoBehaviour {//——————————————-[Header(———-轮碰撞器特征————-)]//四个轮子的碰撞器public WheelCollider[] wheels;[SerializeField]//网格的获取private GameObject[] wheelMesh;//四个轮胎扭矩力的大小public float f_right;public float f_left;public float b_right;public float b_left;//车轮打滑参数识别public float[] slip;//初始化三维向量和四元数private Vector3 wheelPosition Vector3.zero;private Quaternion wheelRotation Quaternion.identity;//——————————————-//驱动模式选择 _默认前驱public EDriveType DriveType EDriveType.frontDrive;[Header(———-车辆属性特征————-)]//车刚体public Rigidbody rigidbody;//轮半径public float radius 0.25f;//扭矩力度public float motorflaot 8000f;//刹车力public float brakVualue 800000f;//速度每小时多少公里public int Km_H;//加速的速度增量public float shiftSpeed 4000;//下压力public float downForceValue 1000f;//质心public Vector3 CenterMass;[Header(———-发动机属性特征————-)]//发动机马力与转速曲线public AnimationCurve enginePowerCurve;//车轮的RPM平均转速public float wheelsRPM;//发动机转速public float engineRPM;//汽车齿轮比挡位public float[] gears;//当前的挡位public int gerrsNurrentNum 0;//差速比public float diffrirentialRation;//离合器private float clutch;//平滑时间参数private float smoothTime 0.09f;//一些属性的初始化private void Start(){rigidbody GetComponentRigidbody();slip new float[4];}private void FixedUpdate(){VerticalAttribute();//车辆物理属性管理WheelsAnimation(); //车轮动画CarEnginePower(); //汽车发动机HorizontalContolr(); //转向管理HandbrakControl(); //手刹管理ShiftSpeed();//加速相关}//车辆物理属性相关public void VerticalAttribute(){//—————速度实时—————//1m/s 3.6km/hKm_H (int)(rigidbody.velocity.magnitude * 3.6);Km_H Mathf.Clamp(Km_H, 0, 200); //油门速度为 0 到 200 Km/H之间//————–扭矩力实时—————//显示每个轮胎的扭矩f_right wheels[0].motorTorque;f_left wheels[1].motorTorque;b_right wheels[2].motorTorque;b_left wheels[3].motorTorque;//————-下压力添加—————–//速度越大下压力越大抓地更强rigidbody.AddForce(-transform.up * downForceValue * rigidbody.velocity.magnitude);//————-质量中心同步—————-//质量中心越贴下越不容易翻rigidbody.centerOfMass CenterMass;}//垂直轴方向运动管理驱动管理public void VerticalContorl(){switch (DriveType){case EDriveType.frontDrive://选择前驱if (InputManager.InputManagerment.vertical ! 0) //当按下WS键时生效{for (int i 0; i wheels.Length - 2; i){//扭矩力度wheels[i].motorTorque InputManager.InputManagerment.vertical * (motorflaot / 2); //扭矩马力归半}}else{for (int i 0; i wheels.Length - 2; i){//扭矩力度wheels[i].motorTorque 0;}}break;case EDriveType.backDrive://选择后驱if (InputManager.InputManagerment.vertical ! 0) //当按下WS键时生效{for (int i 2; i wheels.Length; i){//扭矩力度wheels[i].motorTorque InputManager.InputManagerment.vertical * (motorflaot / 2); //扭矩马力归半}}else{for (int i 2; i wheels.Length; i){//扭矩力度wheels[i].motorTorque 0;}}break;case EDriveType.allDrive://选择四驱if (InputManager.InputManagerment.vertical ! 0) //当按下WS键时生效{for (int i 0; i wheels.Length; i){//扭矩力度wheels[i].motorTorque InputManager.InputManagerment.vertical * (motorflaot / 4); //扭矩马力/4}}else{for (int i 0; i wheels.Length; i){//扭矩力度wheels[i].motorTorque 0;}}break;default:break;}}//水平轴方向运动管理转向管理public void HorizontalContolr(){if (InputManager.InputManagerment.horizontal 0){//后轮距尺寸设置为1.5f 轴距设置为2.55f radius 默认为6radius 越大旋转的角度看起来越小wheels[0].steerAngle Mathf.Rad2Deg * Mathf.Atan(2.55f / (radius (1.5f / 2))) * InputManager.InputManagerment.horizontal;wheels[1].steerAngle Mathf.Rad2Deg * Mathf.Atan(2.55f / (radius - (1.5f / 2))) * InputManager.InputManagerment.horizontal;}else if (InputManager.InputManagerment.horizontal 0){wheels[0].steerAngle Mathf.Rad2Deg * Mathf.Atan(2.55f / (radius - (1.5f / 2))) * InputManager.InputManagerment.horizontal;wheels[1].steerAngle Mathf.Rad2Deg * Mathf.Atan(2.55f / (radius (1.5f / 2))) * InputManager.InputManagerment.horizontal;}else{wheels[0].steerAngle 0;wheels[1].steerAngle 0;}}//手刹管理public void HandbrakControl(){if (InputManager.InputManagerment.handbanl){//后轮刹车wheels[2].brakeTorque brakVualue;wheels[3].brakeTorque brakVualue;}else{wheels[2].brakeTorque 0;wheels[3].brakeTorque 0;}//————刹车效果平滑度显示————for (int i 0; i slip.Length; i){WheelHit wheelhit;wheels[i].GetGroundHit(out wheelhit);slip[i] wheelhit.forwardSlip; //轮胎在滚动方向上打滑。加速滑移为负制动滑为正}}//车轮动画相关public void WheelsAnimation(){for (int i 0; i wheels.Length; i){//获取当前空间的车轮位置 和 角度wheels[i].GetWorldPose(out wheelPosition, out wheelRotation);//赋值给wheelMesh[i].transform.position wheelPosition;wheelMesh[i].transform.rotation wheelRotation * Quaternion.AngleAxis(90, Vector3.forward);}}//加速以及动画相关public void ShiftSpeed(){//按下shift加速键时if (InputManager.InputManagerment.shiftSpeed){//向前增加一个力rigidbody.AddForce(-transform.forward * shiftSpeed);}else{rigidbody.AddForce(transform.forward * 0);}}//汽车引擎发动机相关public void CarEnginePower(){WheelRPM();//将轮轴的转速获取// 扭矩力发动机功率 功率扭矩*转速*nmotorflaot -enginePowerCurve.Evaluate(engineRPM) * gears[gerrsNurrentNum];float velocity 0.0f;//发动机的转速 与 车轮转速 和 挡位比率 成比例engineRPM Mathf.SmoothDamp(engineRPM, 1000 Mathf.Abs (wheelsRPM) * 3.6f * (gears[gerrsNurrentNum]), ref velocity, smoothTime);print(engineRPM);VerticalContorl(); //驱动管理shifterGearsChange(); //换挡管理}//获得车轮的转速public void WheelRPM(){float sum 0;for (int i 0; i 4; i){sum wheels[i].rpm;}//四个车轮轮轴的平均转速wheelsRPM sum / 4;}//换挡管理public void shifterGearsChange(){if(InputManager.InputManagerment .addGears ) //如果按下E键,加挡{if(gerrsNurrentNum gears.Length - 1 )gerrsNurrentNum;}if(InputManager.InputManagerment.lowGears ) //如果按下Q键减档{if (gerrsNurrentNum 0)gerrsNurrentNum–;}} } ️CameraContorl using System.Collections; using System.Collections.Generic; using UnityEngine; //————————————- //————————————————————————————————————— //___________项目: ______________ //________功能 相机的管理 //_____创建者秩沅____________ //_____________________________________ //————————————- public class CameraContorl : MonoBehaviour {//目标物体public Transform target;private CarMoveControl Control;public float speed;[Header(———-相机基础属性————-)]//鼠标滑轮的速度public float ScrollSpeed 45f;public float Ydictance 0f;private float Ymin 0f;private float Ymax 4f;public float Zdictance 4f;private float Zmin 4f;private float Zmax 15f;//相机看向的角度 和最終位置public float angle -25 ;private Vector3 lastPosition;private Vector3 lookPosition;[Header(———-加速时相机属性————-)]//加速时的跟随力度[Range(1, 5)]public float shiftOff;//目标视野 让其显示可见[SerializeField ]private float addFov;//当前视野private float startView;public float off 20;//为一些属性初始化private void Start(){startView Camera.main.fieldOfView; //将相机的开始属性赋入addFov 30;}void LateUpdate(){FllowEffect(); //相机属性显示CameraAtrribute(); //相机跟随功能FOXChange(); //加速时相机视野的变化}//相机属性显示public void CameraAtrribute(){//实时速度Control target.GetComponentCarMoveControl();speed Mathf .Lerp (speed , Control.Km_H / 4 ,Time.deltaTime ) ;speed Mathf.Clamp(speed, 0, 55); //对应最大200公里每小时}//相机跟随功能public void FllowEffect() {//Z轴和Y轴的距离和鼠标滑轮联系Ydictance Input.GetAxis(Mouse ScrollWheel) * ScrollSpeed * Time.deltaTime;//平滑效果Zdictance Input.GetAxis(Mouse ScrollWheel) * ScrollSpeed * Time.deltaTime*2;//設置Y軸和x轴的滚轮滑动范围 Ydictance Mathf.Clamp(Ydictance, Ymin, Ymax);Zdictance Mathf.Clamp(Zdictance, Zmin, Zmax);//确定好角度四元数 * 三维向量 三维向量 和最终位置lookPosition Quaternion.AngleAxis(angle, target.right) * -target.forward;lastPosition target.position Vector3.up * Ydictance - lookPosition * Zdictance;差值更新位置,速度越快镜头跟随越快速度越慢镜头跟随越慢transform.position lastPosition; //更新角度transform.rotation Quaternion.LookRotation(lookPosition);}//加速时相机视野的变化public void FOXChange(){if(Input.GetKey(KeyCode.LeftShift) ) //按下坐标shift键生效{Camera.main.fieldOfView Mathf.Lerp(Camera.main.fieldOfView , startView addFov ,Time .deltaTime * shiftOff );}else{Camera.main.fieldOfView Mathf.Lerp(Camera.main.fieldOfView, startView, Time.deltaTime * shiftOff);}}} ️UIContorl using System.Collections; using System.Collections.Generic; using UnityEngine; //————————————- //————————————————————————————————————— //___________项目: ______________ //________功能 UI相关的脚本管理 //_____创建者_秩沅_____ //_____________________________________ //————————————- public class UIContorl : MonoBehaviour {//——————仪表盘—————-//速度指针开始角度和最终角度private float startAngel 215, ednAngel -35;//速度指针偏差角度private float offAngel;//获取速度的对象public CarMoveControl control;//速度指针组件public Transform node;//—————————————-void Update(){//偏差角度 每度速度旋转的角度 * 速度offAngel (startAngel - ednAngel) / 180 * control.Km_H;//offAngel (startAngel - ednAngel) * control.engineRPM /10000;//仪表盘的管理与速度同步node.eulerAngles new Vector3 (0, 0, startAngel -offAngel);} } ️ InputManager using System.Collections; using System.Collections.Generic; using UnityEngine; //————————————- //————————————————————————————————————— //___________项目: ______________ //________功能 输入控制管理器 //_____创建者秩沅____________ //_____________________________________ //————————————- public class InputManager : MonoBehaviour {//单例模式管理static private InputManager inputManagerment;static public InputManager InputManagerment inputManagerment;public float horizontal; //水平方向动力值public float vertical; //垂直方向动力值public bool handbanl; //手刹动力值public bool shiftSpeed; //加速shift键//public float clutch; //离合器public bool addGears; //升档public bool lowGears; //降档void Awake(){inputManagerment this;}void FixedUpdate(){//与Unity中输入管理器的值相互对应horizontal Input.GetAxis(Horizontal);vertical Input.GetAxis(Vertical);handbanl Input.GetAxis(Jump)! 0 ? true :false ; //按下空格键时就是1否则为0shiftSpeed Input.GetKey(KeyCode.LeftShift) ? true : false;//clutch Input.GetKey(KeyCode.LeftShift) ? 0 : Mathf.Lerp(clutch ,1,Time .deltaTime);addGears Input.GetKeyDown(KeyCode.E ) ? true : false;lowGears Input.GetKeyDown(KeyCode.Q ) ? true : false;} } ⭐【Unityc#专题篇】之c#进阶篇】 ⭐【Unityc#专题篇】之c#核心篇】 ⭐【Unityc#专题篇】之c#基础篇】 ⭐【Unity-c#专题篇】之c#入门篇】 ⭐【Unityc#专题篇】—进阶章题单实践练习 ⭐【Unityc#专题篇】—基础章题单实践练习 ⭐【Unityc#专题篇】—核心章题单实践练习 你们的点赞 收藏⭐ 留言 关注✅是我持续创作输出优质内容的最大动力、