- TargetSurfaceUtility를 추가해 플레이어와 적의 실제 충돌 표면 기준으로 거리, 방향, 목적지를 계산 - 플레이어 이동과 적 루트모션, 추적 로직에서 접촉 시 수평 이동을 제한해 겹침과 밀어내기 문제를 완화 - 드로그 AI 거리 판정 노드들이 표면 거리 기준을 사용하도록 맞춰 사거리 분기 오차를 줄임
84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using System;
|
|
|
|
using Colosseum;
|
|
using Colosseum.Combat;
|
|
using Colosseum.Enemy;
|
|
using Colosseum.Player;
|
|
|
|
using Unity.Behavior;
|
|
using Unity.Properties;
|
|
using UnityEngine;
|
|
|
|
using Action = Unity.Behavior.Action;
|
|
|
|
/// <summary>
|
|
/// 일정 반경 내에서 가장 가까운 다운 대상 플레이어를 선택하는 Behavior Action입니다.
|
|
/// </summary>
|
|
[Serializable, GeneratePropertyBag]
|
|
[NodeDescription(
|
|
name: "Select Nearest Downed Target",
|
|
story: "[SearchRadius] 반경 내 가장 가까운 다운 대상을 [Target]으로 선택",
|
|
category: "Action",
|
|
id: "ee1146ad46ec4730acb4d6c883a5a771")]
|
|
public partial class SelectNearestDownedTargetAction : Action
|
|
{
|
|
[SerializeReference]
|
|
public BlackboardVariable<GameObject> Target;
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> SearchRadius = new BlackboardVariable<float>(0f);
|
|
|
|
protected override Status OnStart()
|
|
{
|
|
float searchRadius = ResolveSearchRadius();
|
|
HitReactionController[] hitReactionControllers = UnityEngine.Object.FindObjectsByType<HitReactionController>(FindObjectsSortMode.None);
|
|
|
|
GameObject nearestTarget = null;
|
|
float nearestDistance = float.MaxValue;
|
|
|
|
for (int i = 0; i < hitReactionControllers.Length; i++)
|
|
{
|
|
HitReactionController controller = hitReactionControllers[i];
|
|
if (controller == null || !controller.IsDowned)
|
|
continue;
|
|
|
|
GameObject candidate = controller.gameObject;
|
|
if (candidate == null || !candidate.activeInHierarchy)
|
|
continue;
|
|
|
|
if (Team.IsSameTeam(GameObject, candidate))
|
|
continue;
|
|
|
|
IDamageable damageable = candidate.GetComponent<IDamageable>();
|
|
if (damageable != null && damageable.IsDead)
|
|
continue;
|
|
|
|
float distance = TargetSurfaceUtility.GetHorizontalSurfaceDistance(GameObject.transform.position, candidate);
|
|
if (distance > searchRadius || distance >= nearestDistance)
|
|
continue;
|
|
|
|
nearestDistance = distance;
|
|
nearestTarget = candidate;
|
|
}
|
|
|
|
if (nearestTarget == null)
|
|
return Status.Failure;
|
|
|
|
Target.Value = nearestTarget;
|
|
GameObject.GetComponent<BossBehaviorRuntimeState>()?.SetCurrentTarget(nearestTarget);
|
|
LogDebug($"다운 대상 선택: {nearestTarget.name}");
|
|
return Status.Success;
|
|
}
|
|
|
|
private float ResolveSearchRadius()
|
|
{
|
|
return Mathf.Max(0f, SearchRadius.Value);
|
|
}
|
|
|
|
private void LogDebug(string message)
|
|
{
|
|
BossBehaviorRuntimeState context = GameObject.GetComponent<BossBehaviorRuntimeState>();
|
|
context?.LogDebug(nameof(SelectNearestDownedTargetAction), message);
|
|
}
|
|
}
|