位置: 编程技术 - 正文

Unity3d 赛车车辆各类性能算法(unity3d赛车游戏毕业设计)

编辑:rootadmin
欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多Unity3D资源、Unity3D培训视频、Unity3D教程、Unity3D常见问题、Unity3D项目源码,【狗刨学习网】unity极致学院,致力于打造业内unity3d培训、学习第一品牌。   在制作前,必须先了解真实车辆的原理:  车辆分前轮驱动,后轮驱动和四驱动。动力由引擎提供,反应的力到轮胎上,因此产生转数,即RPM。  引擎的功率可以由RPM得到公式为 : RPM = 引擎功率/2pi , 这些都是模拟,只为了更好的为下面的动作服务。还有大众关心的"漂移" ,所谓 漂移就是,在后驱车辆中,前轮方向旋转大角度,地面给于一定向心力,同时后轮又给予更多动力,导致"漂移"动作。  基于上面原理,就更容易理解下面的文章。  我先说明,有非常多种方法来开发一款赛车。本人赛车版本经过无数多种方法,无数次改版后最终选了个大众接受的。这些方法,容我一个个道来。  首先,你要明白,车辆不可能整个套一个外壳,原因是在接触地面时,对车辆所使的力不可能达到你预期的目标,引起,必须在车辆轮胎以上做外壳碰撞,轮胎以下就需要有力来支持它始终保持不掉下来。  Unity3d里有个很神奇的东西 叫WheelCollider , 它是专门模拟轮胎支持力和轮胎转数,以及轮胎横向力,前进力,以及 悬架避震系统。  这个东西非常方便,只要你把这个东西套在4个轮胎上,调试下他的forwardFriction 和 sidewaysFriction  达到你想要的效果,然后对驱动轮的motorTorque进行赋&#;,你的车辆就能动了。  记得你需要无数次调试 前进摩擦力和横向摩擦力 。  至于悬架系统在你需要时也可以改变其&#;。还有,这两个摩擦力,是一个由低到高,再由高到稳定的一条曲线。  这个WheelCollider非常好用,曾一度沉迷于此。但后来发现,他有很多不合理的地方。想要得到最好的效果,还是抛弃了他。  为了支持车辆的碰撞外壳不接触地面,必须写一个悬架动态支持力,在4个轮胎位置,支持整辆车悬浮于地面之上。  关于这个悬架动态支持力在这奉献下:  void SuspensionHoldForce()  {  float fullCompressionSpringForce = this.rigidbody.mass * 0.f * 2.0f * -Physics.gravity.y;  this.OnGround = true;  foreach( GameObject item in FwheelModels )  {  RaycastHit hit;  bool onGround = Physics.Raycast( item.transform.parent.position , -item.transform.parent.InverseTransformDirection(Vector3.up), out hit, this.suspensionTravel &#; this.radius);  if (onGround hit.collider.isTrigger)  {  onGround = false;  float dist = this.suspensionTravel &#; this.radius;  RaycastHit[]  hits = Physics.RaycastAll( item.transform.parent.position , -item.transform.parent.InverseTransformDirection(Vector3.up) , this.suspensionTravel &#; this.radius );  foreach(RaycastHit test in hits)  {  if (!test.collider.isTrigger test.distance = dist)  {  hit = test;  onGround = true;  dist = test.distance;  }  }  }  if( onGround )  {  Vector3 wheelVelo = this.rigidbody.GetPointVelocity (item.transform.parent.position);  Vector3 localVelo = transform.InverseTransformDirection (wheelVelo);  Vector3 groundNormal = transform.InverseTransformDirection (hit.normal);  float damperForce = Vector3.Dot(localVelo, groundNormal) * f;  float compression = 1.0f - ((hit.distance - radius) / suspensionTravel);  Vector3 springForce = ( fullCompressionSpringForce*compression - damperForce ) * item.transform.parent.InverseTransformDirection(Vector3.up);  springForce.z = springForce.x = 0f;  this.rigidbody.AddForceAtPosition( springForce , item.transform.parent.position );  }  else  {  this.OnGround = false;  }  }  foreach( GameObject item in BwheelModels )  {  RaycastHit hit;  bool onGround = Physics.Raycast( item.transform.parent.position, -item.transform.parent.InverseTransformDirection(Vector3.up), out hit, this.suspensionTravel &#; this.radius);  if (onGround hit.collider.isTrigger)  {  onGround = false;  float dist = this.suspensionTravel &#; this.radius;  RaycastHit[]  hits = Physics.RaycastAll( item.transform.parent.position, -item.transform.parent.InverseTransformDirection(Vector3.up) , this.suspensionTravel &#; this.radius );  foreach(RaycastHit test in hits)  {  if (!test.collider.isTrigger test.distance = dist)  {  hit = test;  onGround = true;  dist = test.distance;  }  }  }  if( onGround )  {  Vector3 wheelVelo = this.rigidbody.GetPointVelocity (item.transform.parent.position);  Vector3 localVelo = transform.InverseTransformDirection (wheelVelo);  Vector3 groundNormal = transform.InverseTransformDirection (hit.normal);  float damperForce = Vector3.Dot(localVelo, groundNormal) * f;  float compression = 1.0f - ( ( hit.distance - radius ) / suspensionTravel );  Vector3 springForce = ( fullCompressionSpringForce*compression - damperForce ) * item.transform.parent.InverseTransformDirection(Vector3.up);  springForce.z = springForce.x = 0f;  this.rigidbody.AddForceAtPosition( springForce , item.transform.parent.position );  }  else  {  this.OnGround = false;  }  }  }  那么在完成悬架支撑后,就该设计车辆动力了。  这里也有2种方法:一个方向是真实车辆行驶轨迹,另一个是模拟型车辆轨迹。  前者的方法是 , 将动力点放在车辆驱动轮上,例如后轮。用rigidbody的AddForceAtPosition可以做到,前轮只需要提供横向力就可以实现转弯的轨迹。但别看说说这么容易,这里面还涉及非常多的数&#;和曲线问题。在提供车辆动力时,你需要一条曲线,以致车辆不会匀加速,因为这样很不真实,还有在前轮横向力中,你必需是条由0到最高点,然后下降到平衡点的曲线。这样你的赛车才显得更真实。这些都需要用到几个数学知识。  后者,是用算法来模拟的一种车辆轨迹。这个算法所有作用力作用在车辆的中心点。  转弯轨迹,我是用转弯半径来表示,使得车辆在转弯时有相当的真实性,必须改变车辆转弯速度。当然,用到了些数学知识。代码奉献下:  #region 计算转弯角度  void Steering( bool canSteer , Vector3 relativeVelocity )  {  if( canSteer this.OnGround )  {  if( this.shiftthrottle == 1 )  {  this.transform.RotateAround( this.transform.TransformPoint( ( this.FwheelModels[0].transform.localPosition &#; this.FwheelModels[1].transform.localPosition) * 0.5f ) , this.transform.up , this.rigidbody.velocity.magnitude *2f* this.steeringInput * Time.deltaTime * 2f );  //~ this.rigidbody.AddForceAtPosition( this.FwheelModels[0].transform.TransformDirection(Vector3.right*this.steeringInput) * 3f * this.rigidbody.mass, this.FwheelModels[0].transform.position);  //~ this.rigidbody.AddForceAtPosition( this.FwheelModels[1].transform.TransformDirection(Vector3.right*this.steeringInput) * 3f * this.rigidbody.mass, this.FwheelModels[1].transform.position);  return ;  }  if( this.throttle * this.transform.InverseTransformDirection(this.rigidbody.velocity).z 0 )  return ;  float turnRadius = 3.0f / Mathf.Sin( (f - this.steering) * Mathf.Deg2Rad );  float minMaxTurn = EvaluateSpeedToTurn(this.rigidbody.velocity.magnitude);  float turnSpeed = Mathf.Clamp(relativeVelocity.z / turnRadius, -minMaxTurn / , minMaxTurn / );  this.transform.RotateAround( this.transform.position &#; this.transform.right * turnRadius * this.steeringInput , transform.up , turnSpeed * Mathf.Rad2Deg * Time.deltaTime * this.steeringInput );  //~ Vector3 debugStartPoint = transform.position &#; transform.right * turnRadius * this.steeringInput;  //~ Vector3 debugEndPoint = debugStartPoint &#; Vector3.up * 5f;  //~ Debug.DrawLine(debugStartPoint, debugEndPoint, Color.red);  }  }  float EvaluateSpeedToTurn( float speed )  {  if(speed this.topSpeed / 2)  return minimumTurn;  float speedIndex = 1 - ( speed / ( this.topSpeed / 2 ) );  return minimumTurn &#; speedIndex * (maximumTurn - minimumTurn);  }  #endregion  这个模拟车辆轨迹,不能达到漂移的性能,但我加了一个滑动比例计算的算法,用车辆横向移动速度,和前进速度,的比例来确定,该车辆是否处于漂移状态,如处于,则启动漂移滑动程序。当然,我的赛车是很自然的,不做做。至于轮胎痕迹,就是判断是否触底后,在该点生成轮胎痕迹gameobject,如此而已。  最后,再介绍下,所有车辆都需要模拟的,行驶时,轮胎随速度旋转这个关系到车辆看起来真实性的东西。其实非常简单。不多说,发代码:  #region 轮胎滚动与旋转模拟  void WheelRoll()  {  float averageAngularVelo = ( this.rigidbody.GetPointVelocity(this.BwheelModels[0].transform.parent.position).magnitude &#; this.rigidbody.GetPointVelocity(this.BwheelModels[0].transform.parent.position).magnitude )/2f;  float engineAngularVelo = averageAngularVelo * 3f;  float rpm = engineAngularVelo * (.0f/(2*Mathf.PI)) * (this.transform.InverseTransformDirection(this.rigidbody.velocity).z 0f ? 1f : -1f );  //~ Debug.Log(this.transform.InverseTransformDirection(this.rigidbody.velocity).z);  FwheelModels[0].transform.rotation = FwheelModels[0].transform.parent.rotation * Quaternion.Euler (RotationValue, this.steering , 0);//旋转  FwheelModels[1].transform.rotation = FwheelModels[1].transform.parent.rotation * Quaternion.Euler (RotationValue, this.steering , 0);//旋转  BwheelModels[0].transform.rotation = BwheelModels[0].transform.parent.rotation * Quaternion.Euler (RotationValue, 0, 0);//旋转  BwheelModels[1].transform.rotation = BwheelModels[1].transform.parent.rotation * Quaternion.Euler (RotationValue, 0, 0);//旋转  RotationValue &#;= rpm * ( f/f ) * Time.deltaTime;  }  #endregion更多内容,请访问【狗刨学习网】unity极致学院声明:此篇文档时来自于【狗刨学习网】社区-unity极致学院,是网友自行发布的Unity3D学习文章,如果有什么内容侵犯了你的相关权益,请与官方沟通,我们会即时处理。

推荐整理分享Unity3d 赛车车辆各类性能算法(unity3d赛车游戏毕业设计),希望有所帮助,仅作参考,欢迎阅读内容。

Unity3d 赛车车辆各类性能算法(unity3d赛车游戏毕业设计)

文章相关热门搜索词:unity3d赛车游戏毕业设计,unity出品的单机游戏赛车,unity3d汽车,unity出品的单机游戏赛车,unity赛车模型,unity3d赛车游戏的制作方法,unity3d赛车游戏教程,unity3d赛车游戏的制作方法,内容如对您有帮助,希望把文章链接给更多的朋友!

TFC冯燃:手游市场细分领域新秀崛起 狗刨学习网报道/3月日上午,第十届TFC全球移动游戏大会在北京国际会议中心开幕。本届大会以寻路、跨界、融合为主题,吸引了超过位业内重量

Unity手机游戏录像、录音sdk介入(游戏陀螺WeRecSDK) 这东西不错,如果项目需要录像回放功能,可以使用。但是在介入之前建议先试试手动的

浅析游戏引擎的资源管理机制——扒一扒Unity3D中隐藏在背后的资源管理 游戏中通常有大量资源,如网、材质、纹理、动画、着色器程序和音乐等,游戏引擎作为做游戏的工具,自然要提供良好的资源管理,让游戏开发者用

标签: unity3d赛车游戏毕业设计

本文链接地址:https://www.jiuchutong.com/biancheng/383601.html 转载请保留说明!

上一篇:Unity3D研究之角色控制器组件研究(unity 设置物体角度)

下一篇:TFC360冯燃:手游市场细分领域新秀崛起

  • 矿产资源补偿费计入管理费用吗
  • 进项税转出的会计凭证
  • 小规模纳税人印花税怎样计算
  • 税务师考试税法一章节
  • 如何确定交易性金融资产
  • 对公账户发工资1万要交税吗
  • 不动产服务具体有哪些
  • 如何申请免税
  • 合作建房如何纳税
  • 营改增后11
  • 多计提的工资怎么处理?
  • 抵押车贷款会不会扣车
  • 出租无形资产的收入
  • 资产一次性摊销
  • 营业账簿是什么意思
  • 本月没开票怎么报税
  • 小规模专票丢了怎么办
  • 在产品,产成品和库存商品的区别
  • 计提应付利息编制记账凭证用什么原始凭证?
  • 农产品加计扣除政策2023最新
  • 确认递延收益纳税调整吗
  • 升级声卡驱动后声音禁用了怎么恢复
  • win10专业版激活密钥永久
  • 享受即征即退政策有效期到了还有效吗
  • 三代税款手续费支付比例
  • PHP:pg_field_type()的用法_PostgreSQL函数
  • 500万元固定资产管理办法
  • fpzs1是什么文件可以删除吗
  • pascl32.exe - pascl32是什么进程 有什么用
  • npfmntor.exe - npfmntor是什么进程 有什么用
  • win7纯净版系统激活
  • 委托贷款会计处理流程
  • 银行同业利息 水利基金
  • 来料加工企业需注意什么
  • 退回的税控盘费用如何做会计分类
  • 机器学习中的数学原理——对数似然函数
  • 请简述你对php的理解并描述php的工作流程
  • php实现留言板功能怎么用
  • cobit框架
  • 电话费发放标准2020
  • 选择器优先级
  • 技术部周报怎么写
  • java如何解析json字符串
  • php会员系统
  • php获取参数值的三种方式
  • 劳务公司社保手续办理
  • 房屋租赁交的定金可以退吗
  • MySQL读写分离中间件
  • 执行企业会计制度是什么意思
  • 公司向个人借款怎么做账
  • 预付工程款该怎么记账
  • 一般纳税人的资格登记
  • 货款扣除质量赔款
  • 租房开的发票收的税如何做账?
  • 库存商品暂估入库是什么意思
  • 会计的凭证怎么做账
  • 纳税筹划有哪些特点以及原则?
  • sql语句查询记录
  • navicat查询结果下面输出栏如何关闭
  • 简单介绍linux系统有哪些主要特点?
  • 电脑自建热点
  • ubuntu 无法正常启动
  • linux临时修改编码
  • win7c盘突然满了怎么回事
  • Win10 Build 10586.107正式推送 主要修复bug
  • linux如何使用vim编写程序
  • node.js axios
  • python中matplotlib绘制曲线
  • oculus dk2
  • AngularJS + Node.js + MongoDB开发的基于高德地图位置的通讯录
  • nodejs socket框架
  • python制作简单图形
  • 安卓网络监测
  • python listnode
  • js获取父窗口
  • android知识点大全
  • 在电子税务局如何增加税种
  • 国税纳税服务有哪些项目
  • 纳税申报表有哪几种类型
  • 房地产契税2023年最新政策
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设