Files
Colosseum/Assets/_Game/Scripts/AI/BehaviorActions/Actions/ChaseTargetAction.cs
dal4segno a347d9360d fix: 플레이어-보스 충돌 슬라이딩 및 관통 방지
- CharacterController.enableOverlapRecovery 비활성화로 자동 밀어냄 제거
- 레이어 마스크 의존 제거, 컴포넌트(NavMeshAgent/CharacterController)로 식별
- EnemyBase LateUpdate에서 velocity 기반 보스 위치 보정
- EnemyBase OnAnimatorMove에서 루트모션의 플레이어 방향 이동 차단
- BossEnemy Update를 OnServerUpdate 패턴으로 리팩터링
- 보스 프리팹 하위 오브젝트 레이어 Enemy로 통일

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 00:14:50 +09:00

76 lines
2.0 KiB
C#

using System;
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()
{
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()
{
if (Target.Value == null)
{
return Status.Failure;
}
// 이미 사거리 내에 있으면 성공
float distance = Vector3.Distance(GameObject.transform.position, Target.Value.transform.position);
if (distance <= StopDistance.Value)
{
agent.isStopped = true;
return Status.Success;
}
agent.SetDestination(Target.Value.transform.position);
return Status.Running;
}
protected override void OnEnd()
{
if (agent != null)
{
agent.isStopped = true;
}
}
}