自动行为操控Steering(八)—路径跟随(单体操控)

来源:互联网 发布:手机电影剪辑软件 编辑:程序博客网 时间:2024/06/05 14:35

图示:



实现:

public enum PatrolMode    {        Once,        Loop,        PingPong,    }    ///<summary>    ///路径跟随    ///</summary>    public class FollowToPathSteering : Steering    {        /// <summary>巡逻到达的距离 </summary>        public float patrolArrivalDistance = 1;        /// <summary>路点 </summary>        public Transform[] wayPoints;        /// <summary>巡逻模式 </summary>        public PatrolMode partrolMode = PatrolMode.Once;        private int currentWayPoint;        private bool IsPatrolComplete;        public override Vector3 ComputerFinalForce()        {                         exceptForce = (wayPoints[currentWayPoint].position - transform.position).normalized * speed;                              //是否到达当前路点                if (Vector3.Distance(transform.position, wayPoints[currentWayPoint].position) < patrolArrivalDistance)                {                    //是否是最后一个路点                    if (currentWayPoint == wayPoints.Length - 1)                    {                        //多分支                        switch (partrolMode)                        {                            //单次:                            case PatrolMode.Once:                                IsPatrolComplete = true;                                return Vector3.zero;                                                            //往返:                            case PatrolMode.PingPong:                                Array.Reverse(wayPoints);                                break;                        }                    }                    currentWayPoint = (currentWayPoint + 1) % wayPoints.Length;                }                //移动:                //MoveToTarget(wayPoints[currentWayPoint].position, walkSpeed, patrolArrivalDistance);                //动画:                //fsm.PlayAnimation(fsm.animaParm.Walk);                        return (exceptForce - vehicle.currentForce) * weight;        }    }



阅读全文
1 0
原创粉丝点击