重做杂兵
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
[Tooltip("Agent 正在追踪的目标对象。")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_Target;
|
||||
[Tooltip("指定提前预测目标的距离的程度。")]
|
||||
[SerializeField] protected SharedVariable<float> m_DistancePrediction = 20;
|
||||
[SerializeField] protected SharedVariable<float> m_DistancePrediction = 10;
|
||||
[Tooltip("预测提前距离的乘数。")]
|
||||
[SerializeField] protected SharedVariable<float> m_DistancePredictionMultiplier = 1;
|
||||
#endregion
|
||||
@@ -163,8 +163,8 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
base.Reset();
|
||||
m_StartSpeed = 10f;
|
||||
m_Target = null;
|
||||
m_DistancePrediction = 20;
|
||||
m_DistancePredictionMultiplier = 2; // 与声明一致
|
||||
m_DistancePrediction = 10;
|
||||
m_DistancePredictionMultiplier = 1;
|
||||
m_SlowDownDistance = 6f;
|
||||
m_MinSpeed = 0.5f;
|
||||
m_SpeedCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Opsive.BehaviorDesigner.AddOns.MovementPack.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.AddOns.Shared.Runtime.Pathfinding;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Utility;
|
||||
using Opsive.GraphDesigner.Runtime;
|
||||
@@ -6,6 +7,7 @@ using Opsive.GraphDesigner.Runtime.Variables;
|
||||
using Opsive.Shared.Utility;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Cielonos.MainGame.Characters.AI
|
||||
{
|
||||
@@ -14,8 +16,11 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
[Category("Cielonos/Movement")]
|
||||
public class WanderInRange : MovementBase
|
||||
{
|
||||
[Tooltip("初始移动速度。")]
|
||||
[SerializeField] protected SharedVariable<float> m_StartSpeed = 10f;
|
||||
|
||||
[Tooltip("以初始出生点为圆心的游走半径(单位:米)。")]
|
||||
[SerializeField] protected SharedVariable<float> m_WanderRadius = 8f;
|
||||
[SerializeField] protected SharedVariable<float> m_WanderRadius = 10f;
|
||||
|
||||
[Tooltip("到达目标点后等待的时间范围(秒)。Min 与 Max 均为 0 时不等待,直接返回 Success。")]
|
||||
[SerializeField] protected SharedVariable<RangeFloat> m_WaitAtDestinationDuration = new RangeFloat(0f, 0f);
|
||||
@@ -33,6 +38,8 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
|
||||
// 记录行为树初始化时的出生点位置
|
||||
private Vector3 m_SpawnPosition;
|
||||
private NavMeshAgentPathfinder _navPathfinder;
|
||||
private NavMeshAgent _agent;
|
||||
|
||||
// 到达后等待状态
|
||||
private float m_WaitDuration = -1f;
|
||||
@@ -47,6 +54,13 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_navPathfinder = m_Pathfinder as NavMeshAgentPathfinder;
|
||||
if (_navPathfinder == null)
|
||||
{
|
||||
Debug.LogError("[PrecisePursue] Requires NavMeshAgentPathfinder.");
|
||||
return;
|
||||
}
|
||||
_agent = _navPathfinder.m_NavMeshAgent;
|
||||
m_SpawnPosition = transform.position;
|
||||
}
|
||||
|
||||
@@ -75,6 +89,8 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
_agent.speed = m_StartSpeed.Value;
|
||||
|
||||
// 到达判定:HasArrived() 或剩余距离小于阈值
|
||||
if (HasArrived() || RemainingDistance < m_ArrivalDistance.Value)
|
||||
{
|
||||
@@ -94,9 +110,9 @@ namespace Cielonos.MainGame.Characters.AI
|
||||
|
||||
// 等待中:检查是否已等待足够时间
|
||||
if (Time.time >= m_DestinationReachedTime + m_WaitDuration)
|
||||
{
|
||||
return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
|
||||
return TaskStatus.Running;
|
||||
|
||||
Reference in New Issue
Block a user