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

Interpolate Spherical#

Math / Interpolate Spherical

  • Can Read

  • Cannot Write

Description#

Interpolates between two rotations following a spherical interpolation

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Interpolate Spherical")]
    [Category("Math/Interpolate Spherical")]
    
    [Description("Interpolates between two rotations following a spherical interpolation")]
    [Image(typeof(IconInterpolate), ColorTheme.Type.Yellow, typeof(BadgeDot))]
    
    [Keywords("Slerp", "Lerp")]
    
    [Serializable]
    public class TypeQuaternionMathInterpolateSpherical : TypeQuaternion
    {
        [SerializeField] private GetQuaternion m_RotationA = new GetQuaternion();
        [SerializeField] private GetQuaternion m_RotationB = new GetQuaternion();
        
        [SerializeField] private GetNumber m_Ratio = new GetNumber();
        [SerializeField] private GetBool m_Clamp = new GetBool();

        public override Quaternion GetPreview(GameObject source) =>
            Interpolate(
                this.m_RotationA.GetPreview(source),
                this.m_RotationB.GetPreview(source),
                (float) this.m_Ratio.GetPreview(source),
                this.m_Clamp.GetPreview(source)
            );

        public override Quaternion Get(Args args)
        {
            Quaternion a = this.m_RotationA.Get(args);
            Quaternion b = this.m_RotationB.Get(args);
            
            float ratio = (float) this.m_Ratio.Get(args);
            bool clamp = this.m_Clamp.Get(args);
            
            return Interpolate(a, b, ratio, clamp);
        }

        private static Quaternion Interpolate(Quaternion a, Quaternion b, double ratio, bool clamp)
        {
            return clamp
                ? Quaternion.Slerp(a, b, (float) ratio)
                : Quaternion.SlerpUnclamped(a, b, (float) ratio);
        }

        public override string ToString()
        {
            return $"S-Lerp({this.m_RotationA}, {this.m_RotationB}, {this.m_Ratio})";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.