Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Rotate Towards#

Math / Rotate Towards

  • Can Read

  • Cannot Write

Description#

Turns a rotation towards another one without ever overshooting it

Parameters#

Name Description
Current The rotation the movement starts from
Target The rotation the movement is heading to
Max Degrees The largest change in degrees allowed in a single step

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Rotate Towards")]
    [Category("Math/Rotate Towards")]

    [Description("Turns a rotation towards another one without ever overshooting it")]
    [Image(typeof(IconRotation), ColorTheme.Type.Yellow, typeof(BadgeSpeed))]

    [Parameter("Current", "The rotation the movement starts from")]
    [Parameter("Target", "The rotation the movement is heading to")]
    [Parameter("Max Degrees", "The largest change in degrees allowed in a single step")]

    [Keywords("Quaternion", "Approach", "Step", "Towards", "Turn", "Clamp")]

    [Serializable]
    public class TypeQuaternionMathRotateTowards : TypeQuaternion
    {
        [SerializeField] private GetQuaternion m_Current = new GetQuaternion();
        [SerializeField] private GetQuaternion m_Target = new GetQuaternion();
        [SerializeField] private GetNumber m_MaxDegrees = new GetNumber(1f);

        public override Quaternion GetPreview(GameObject source) => Quaternion.RotateTowards(
            this.m_Current.GetPreview(source),
            this.m_Target.GetPreview(source),
            (float) this.m_MaxDegrees.GetPreview(source)
        );

        public override Quaternion Get(Args args)
        {
            return Quaternion.RotateTowards(
                this.m_Current.Get(args),
                this.m_Target.Get(args),
                this.m_MaxDegrees.GetFloat(args)
            );
        }

        public override string ToString()
        {
            return $"{this.m_Current} towards {this.m_Target}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.