您的位置:首页 > 其它

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

2017-08-24 13:42 225 查看
图示:



实现:

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;
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: