- TargetSurfaceUtility를 추가해 플레이어와 적의 실제 충돌 표면 기준으로 거리, 방향, 목적지를 계산 - 플레이어 이동과 적 루트모션, 추적 로직에서 접촉 시 수평 이동을 제한해 겹침과 밀어내기 문제를 완화 - 드로그 AI 거리 판정 노드들이 표면 거리 기준을 사용하도록 맞춰 사거리 분기 오차를 줄임
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System;
|
|
|
|
using Colosseum.Combat;
|
|
|
|
using Unity.Behavior;
|
|
using UnityEngine;
|
|
|
|
using Action = Unity.Behavior.Action;
|
|
using Unity.Properties;
|
|
|
|
[Serializable, GeneratePropertyBag]
|
|
[NodeDescription(name: "RotateToTarget", story: "[대상을] 바라보도록 회전", category: "Action", id: "30341f7e1af0565c0aca0253341b3e28")]
|
|
public partial class RotateToTargetAction : Action
|
|
{
|
|
[SerializeReference]
|
|
public BlackboardVariable<GameObject> Target;
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> RotationSpeed = new BlackboardVariable<float>(10f);
|
|
|
|
[SerializeReference]
|
|
public BlackboardVariable<float> AngleThreshold = new BlackboardVariable<float>(5f);
|
|
|
|
protected override Status OnUpdate()
|
|
{
|
|
if (Target.Value == null)
|
|
{
|
|
return Status.Failure;
|
|
}
|
|
|
|
Vector3 direction = TargetSurfaceUtility.GetHorizontalDirectionToSurface(GameObject.transform.position, Target.Value);
|
|
|
|
if (direction == Vector3.zero)
|
|
{
|
|
return Status.Success;
|
|
}
|
|
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
|
float angleDifference = Quaternion.Angle(GameObject.transform.rotation, targetRotation);
|
|
|
|
// 임계값 이내면 성공
|
|
if (angleDifference <= AngleThreshold.Value)
|
|
{
|
|
return Status.Success;
|
|
}
|
|
|
|
// 부드럽게 회전
|
|
GameObject.transform.rotation = Quaternion.Slerp(
|
|
GameObject.transform.rotation,
|
|
targetRotation,
|
|
RotationSpeed.Value * Time.deltaTime
|
|
);
|
|
|
|
return Status.Running;
|
|
}
|
|
}
|