summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Vector3/RotateTowards.cs
blob: e012d875b773ba862899572dd91263e897d9691a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityVector3
{
    [TaskCategory("Basic/Vector3")]
    [TaskDescription("Rotate the current rotation to the target rotation.")]
    public class RotateTowards : Action
    {
        [Tooltip("The current rotation in euler angles")]
        public SharedVector3 currentRotation;
        [Tooltip("The target rotation in euler angles")]
        public SharedVector3 targetRotation;
        [Tooltip("The maximum delta of the degrees")]
        public SharedFloat maxDegreesDelta;
        [Tooltip("The maximum delta of the magnitude")]
        public SharedFloat maxMagnitudeDelta;
        [Tooltip("The rotation resut")]
        [RequiredField]
        public SharedVector3 storeResult;

        public override TaskStatus OnUpdate()
        {
            storeResult.Value = Vector3.RotateTowards(currentRotation.Value, targetRotation.Value, maxDegreesDelta.Value * Mathf.Deg2Rad * Time.deltaTime, maxMagnitudeDelta.Value);
            return TaskStatus.Success;
        }

        public override void OnReset()
        {
            currentRotation = targetRotation = storeResult = Vector3.zero;
            maxDegreesDelta = maxMagnitudeDelta = 0;
        }
    }
}