- Assets/_Game/ 하위로 게임 에셋 통합 - External/ 패키지 벤더별 분류 (Synty, Animations, UI) - 에셋 네이밍 컨벤션 확립 및 적용 (Data_Skill_, Data_SkillEffect_, Prefab_, Anim_, Model_, BT_ 등) - pre-commit hook으로 네이밍 컨벤션 자동 검사 추가 - RESTRUCTURE_CHECKLIST.md 작성 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
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 = Target.Value.transform.position - GameObject.transform.position;
|
|
direction.y = 0f;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|