49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace Invector.vCharacterController.AI.FSMBehaviour
|
|
{
|
|
|
|
public class vUpdateTargetAngle : vStateAction
|
|
{
|
|
public override string categoryName
|
|
{
|
|
get { return "Custom Example/"; }
|
|
}
|
|
|
|
public override string defaultName
|
|
{
|
|
get { return "Update Target Angle"; }
|
|
}
|
|
|
|
public bool setSignedAngle;
|
|
public float dampTime = 0f;
|
|
public string parameterName = "TurnOnSpotDir";
|
|
|
|
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
|
|
{
|
|
// This custom decision that will verify the bool 'moveToTarget' and return if it's true or false
|
|
Vector3 target = fsmBehaviour.aiController.gameObject.transform.position;
|
|
|
|
if (fsmBehaviour.aiController.targetWaypoint)
|
|
{
|
|
target = fsmBehaviour.aiController.targetWaypoint.transform.position;
|
|
}
|
|
|
|
if (fsmBehaviour.aiController.currentTarget.transform)
|
|
{
|
|
target = fsmBehaviour.aiController.currentTarget.transform.position;
|
|
}
|
|
|
|
Debug.DrawLine(fsmBehaviour.aiController.gameObject.transform.position, target);
|
|
|
|
Vector3 targetDir = target - fsmBehaviour.gameObject.transform.position;
|
|
targetDir.y = 0f;
|
|
float angle = Vector3.SignedAngle(targetDir, fsmBehaviour.gameObject.transform.forward, Vector3.up);
|
|
if (setSignedAngle && fsmBehaviour.aiController.animator)
|
|
{
|
|
fsmBehaviour.aiController.animator.SetFloat(parameterName, angle, dampTime, Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
}
|