- TargetSurfaceUtility를 추가해 플레이어와 적의 실제 충돌 표면 기준으로 거리, 방향, 목적지를 계산 - 플레이어 이동과 적 루트모션, 추적 로직에서 접촉 시 수평 이동을 제한해 겹침과 밀어내기 문제를 완화 - 드로그 AI 거리 판정 노드들이 표면 거리 기준을 사용하도록 맞춰 사거리 분기 오차를 줄임
95 lines
2.6 KiB
C#
95 lines
2.6 KiB
C#
using System;
|
|
|
|
using Colosseum.Combat;
|
|
using Colosseum.Enemy;
|
|
|
|
using Unity.Behavior;
|
|
using UnityEngine;
|
|
|
|
using Action = Unity.Behavior.Action;
|
|
using Unity.Properties;
|
|
|
|
[Serializable, GeneratePropertyBag]
|
|
[NodeDescription(name: "ChaseTarget", story: "타겟 추적", category: "Action", id: "0889fbb015b8bf414ef569af08bb6868")]
|
|
public partial class ChaseTargetAction : Action
|
|
{
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<GameObject> Target;
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> Speed = new BlackboardVariable<float>(0f);
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> StopDistance = new BlackboardVariable<float>(2f);
|
|
|
|
private UnityEngine.AI.NavMeshAgent agent;
|
|
|
|
protected override Status OnStart()
|
|
{
|
|
BossBehaviorRuntimeState context = GameObject.GetComponent<BossBehaviorRuntimeState>();
|
|
if (context != null && context.IsBehaviorSuppressed)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
if (Target.Value == null)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
agent = GameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
|
|
if (agent == null)
|
|
{
|
|
Debug.LogWarning("[ChaseTarget] NavMeshAgent not found");
|
|
return Status.Failure;
|
|
}
|
|
|
|
// Speed가 0 이하면 NavMeshAgent의 기존 speed 유지 (EnemyData에서 설정한 값)
|
|
if (Speed.Value > 0f)
|
|
{
|
|
agent.speed = Speed.Value;
|
|
}
|
|
agent.stoppingDistance = StopDistance.Value;
|
|
agent.isStopped = false;
|
|
|
|
return Status.Running;
|
|
}
|
|
|
|
protected override Status OnUpdate()
|
|
{
|
|
BossBehaviorRuntimeState context = GameObject.GetComponent<BossBehaviorRuntimeState>();
|
|
if (context != null && context.IsBehaviorSuppressed)
|
|
{
|
|
if (agent != null)
|
|
agent.isStopped = true;
|
|
|
|
return Status.Failure;
|
|
}
|
|
|
|
if (Target.Value == null)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
// 이미 사거리 내에 있으면 성공
|
|
float distance = TargetSurfaceUtility.GetHorizontalSurfaceDistance(GameObject.transform.position, Target.Value);
|
|
if (distance <= StopDistance.Value)
|
|
{
|
|
agent.isStopped = true;
|
|
return Status.Success;
|
|
}
|
|
|
|
agent.SetDestination(TargetSurfaceUtility.GetClosestSurfacePoint(GameObject.transform.position, Target.Value));
|
|
return Status.Running;
|
|
}
|
|
|
|
protected override void OnEnd()
|
|
{
|
|
if (agent != null)
|
|
{
|
|
agent.isStopped = true;
|
|
}
|
|
}
|
|
}
|