上一篇文章介绍了使用unity3D进行战斗机飞行模拟的设计http://www.cnblogs.com/jqg-aliang/p/4598515.html,其实只要稍微修改一下,就变成了直升机的飞行模拟。只需要复写一下几个移动的方法就行了。
需要写的功能如下:直升机的前进,后退,左右移动,左右旋转,升高和降落
还是以数学模拟为例,我们需要几个值来控制游戏对象(直升机)的移动效果。具体参数的我就不说了,直接上代码吧。
using UnityEngine; using System.Collections; public class GameHelicopter : Flight { //这个是直升机的算法实现 //需要写的功能如下:直升机的前进,后退,左右移动,左右旋转,升降,
bool IsFBB = false, IsLRB = false; //private float downSpeed; private float currentUDSpeed; private float currentMLRSpeed; private float currentRLRSpeed; public override void MoveFB(float speed) { if ((IsSing) || IsOnGround) return; CurrentSpeed += speed * aircaft.Acc * Time.deltaTime; CurrentSpeed = Mathf.Clamp(CurrentSpeed, aircaft.MinSpeed, aircaft.MaxSpeed); if ((IsSing) || IsOnGround) return; IsFBB = false; Balance(Quaternion.Euler(aircaft.AxisFB * speed, body.eulerAngles.y, body.eulerAngles.z), aircaft.RoteFBSpeed * Time.deltaTime/5); } public override void MoveLR(float speed) { //左右移动 if ((IsSing) || IsOnGround) return; //IsLRB = false; currentMLRSpeed