[AI] Behavior Actions 시스템 추가
Ultraworked with [Sisyphus](https://github.com/code-yeonggu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user