阶段性完成
This commit is contained in:
@@ -92,7 +92,7 @@ namespace Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks
|
||||
/// <returns>Success when the agent arrives.</returns>
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (m_Target.Value == null) {
|
||||
if (m_Target == null || m_Target.Value == null) {
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
@@ -155,20 +155,38 @@ namespace Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks
|
||||
m_SlowDownDistance = 6f;
|
||||
m_MinSpeed = 0.5f;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 任务结束时,重置 NavMeshAgent 的状态
|
||||
/// 任务结束时(无论是成功到达,还是被Parallel Selector打断),彻底重置状态
|
||||
/// </summary>
|
||||
public override void OnEnd()
|
||||
{
|
||||
base.OnEnd();
|
||||
|
||||
// 恢复 Agent 的默认设置,这非常重要!
|
||||
if (m_Pathfinder != null)
|
||||
|
||||
if (m_Pathfinder != null && m_Pathfinder.m_NavMeshAgent != null)
|
||||
{
|
||||
// 1. 【核心修复】立即物理刹车
|
||||
// 只有在 Agent 处于激活且在 NavMesh 上时才操作,防止报错
|
||||
if (m_Pathfinder.m_NavMeshAgent.isOnNavMesh && m_Pathfinder.m_NavMeshAgent.isActiveAndEnabled)
|
||||
{
|
||||
// 强制停止寻路逻辑
|
||||
m_Pathfinder.m_NavMeshAgent.isStopped = true;
|
||||
|
||||
// 抹除物理惯性 (这是导致滑步的罪魁祸首)
|
||||
m_Pathfinder.m_NavMeshAgent.velocity = Vector3.zero;
|
||||
|
||||
// 清空当前的路径数据 (防止下一个任务开始前,Agent试图跑完旧路径)
|
||||
m_Pathfinder.m_NavMeshAgent.ResetPath();
|
||||
}
|
||||
|
||||
// 2. 恢复参数设置 (把 Agent 还原成标准状态,供下一个 Task 使用)
|
||||
m_Pathfinder.m_NavMeshAgent.autoBraking = true;
|
||||
m_Pathfinder.m_NavMeshAgent.speed = m_OriginalMaxSpeed;
|
||||
m_Pathfinder.m_NavMeshAgent.isStopped = false;
|
||||
m_Pathfinder.m_NavMeshAgent.speed = m_OriginalMaxSpeed;
|
||||
|
||||
// 注意:不要在这里设为 isStopped = false。
|
||||
// 下一个 Task (比如 Attack 或 Move) 开始时,
|
||||
// 它们会自动调用 SetDestination 或相关逻辑来启动 Agent。
|
||||
// 在这里保持 Stopped 是最安全的“待机”状态。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,12 @@ namespace Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks
|
||||
{
|
||||
[Tooltip("Is the agent rotating in 2D?")]
|
||||
[SerializeField] protected bool m_Use2DPhysics;
|
||||
[Tooltip("Should the angular speed be used instead of the maximum rotation delta?")]
|
||||
[SerializeField] protected bool m_UseAngularSpeed;
|
||||
[Tooltip("The maximum number of angles the agent can rotate in a single tick (in degrees).")]
|
||||
[SerializeField] protected SharedVariable<float> m_MaxRotationDelta = 1;
|
||||
[Tooltip("The angular speed of the agent (in degrees per second).")]
|
||||
[SerializeField] protected SharedVariable<float> m_AngularSpeed = 90f;
|
||||
[Tooltip("Specifies the angle when the agent has arrived at the target rotation (in degrees).")]
|
||||
[SerializeField] protected SharedVariable<float> m_ArrivedAngle = 0.5f;
|
||||
[Tooltip("Should the rotation only affect the Y axis?")]
|
||||
@@ -43,7 +47,15 @@ namespace Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks
|
||||
}
|
||||
|
||||
// Keep rotating towards the target.
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, m_MaxRotationDelta.Value);
|
||||
if (!m_UseAngularSpeed)
|
||||
{
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, m_MaxRotationDelta.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, m_AngularSpeed.Value * Time.deltaTime);
|
||||
}
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
@@ -76,7 +88,9 @@ namespace Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks
|
||||
base.Reset();
|
||||
|
||||
m_Use2DPhysics = false;
|
||||
m_UseAngularSpeed = false;
|
||||
m_MaxRotationDelta = 1;
|
||||
m_AngularSpeed = 90f;
|
||||
m_ArrivedAngle = 0.5f;
|
||||
m_OnlyY = true;
|
||||
m_Target = null;
|
||||
|
||||
Reference in New Issue
Block a user