自动行为操控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;
}
}
实现:
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;
}
}
相关文章推荐
- 自动行为操控Steering(五)—拦截(单体操控)
- 自动行为操控Steering(二)—靠近(单体操控)
- 自动行为操控Steering(六)—逃避(与拦截方向相反,单体操控)
- 自动行为操控Steering(七)—避开障碍物(单体操控)
- 自动行为操控Steering(九)—徘徊(单体操控)
- 自动行为操控Steering(三)—远离(单体操控)
- 自动行为操控Steering(四)—到达(单体操控)
- 自动行为操控Steering(十)—聚集(群体操控)
- 自动行为操控(Steering)(一)—框架
- 自动行为操控Steering(十一)—分散(群体操控)
- unity3d AI 学习--个体行为操控(1)--具体行为类(3)-路径跟随和躲避障碍
- [Silverlight动画]转向行为 - 路径跟随
- [AI-Steering编程]九.路径跟随
- Unity3DAI行为------路径跟随
- Android取消EditText自动获取焦点默认行为
- ASP.NET MVC 关于MasterPage中<script>标签的文件路径自动解析
- Android取消EditText自动获取焦点默认行为
- mac设置自动挂载分区到指定路径
- Windows 10 更新后的自动重启行为
- shell脚本自动查找指定路径下包含某关键字的所有文件