- TargetSurfaceUtility를 추가해 플레이어와 적의 실제 충돌 표면 기준으로 거리, 방향, 목적지를 계산 - 플레이어 이동과 적 루트모션, 추적 로직에서 접촉 시 수평 이동을 제한해 겹침과 밀어내기 문제를 완화 - 드로그 AI 거리 판정 노드들이 표면 거리 기준을 사용하도록 맞춰 사거리 분기 오차를 줄임
81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using System;
|
|
using Unity.Behavior;
|
|
using UnityEngine;
|
|
using Action = Unity.Behavior.Action;
|
|
using Unity.Properties;
|
|
using Colosseum.Combat;
|
|
using Colosseum.Enemy;
|
|
|
|
[Serializable, GeneratePropertyBag]
|
|
[NodeDescription(name: "SetTargetInRange", story: "[Range] 내에 [Tag] 있는지 확인", category: "Action", id: "93b7a5d823a58618d5371c01ef894948")]
|
|
public partial class SetTargetInRangeAction : Action
|
|
{
|
|
[SerializeReference]
|
|
public BlackboardVariable<GameObject> Target;
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<string> Tag = new BlackboardVariable<string>("Player");
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> Range = new BlackboardVariable<float>(10f);
|
|
|
|
protected override Status OnStart()
|
|
{
|
|
if (string.IsNullOrEmpty(Tag.Value))
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
// 모든 타겟 태그 오브젝트 찾기
|
|
GameObject[] targets = GameObject.FindGameObjectsWithTag(Tag.Value);
|
|
|
|
if (targets == null || targets.Length == 0)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
EnemyBase enemy = GameObject.GetComponent<EnemyBase>();
|
|
if (enemy != null && enemy.UseThreatSystem)
|
|
{
|
|
GameObject threatTarget = enemy.GetHighestThreatTarget(Target?.Value, Tag.Value, Range.Value);
|
|
if (threatTarget != null)
|
|
{
|
|
Target.Value = threatTarget;
|
|
return Status.Success;
|
|
}
|
|
}
|
|
|
|
// 가장 가까운 살아있는 타겟 찾기
|
|
GameObject nearestTarget = null;
|
|
float nearestDistance = Range.Value; // Range 내에서만 검색
|
|
|
|
foreach (GameObject potentialTarget in targets)
|
|
{
|
|
// 사망한 타겟은 제외
|
|
IDamageable damageable = potentialTarget.GetComponent<IDamageable>();
|
|
if (damageable != null && damageable.IsDead)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
float distance = TargetSurfaceUtility.GetHorizontalSurfaceDistance(
|
|
GameObject.transform.position,
|
|
potentialTarget);
|
|
|
|
if (distance < nearestDistance)
|
|
{
|
|
nearestDistance = distance;
|
|
nearestTarget = potentialTarget;
|
|
}
|
|
}
|
|
|
|
if (nearestTarget == null)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
Target.Value = nearestTarget;
|
|
return Status.Success;
|
|
}
|
|
}
|