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#

Math / Interpolate Positions

  • Can Read

  • Cannot Write

Description#

Interpolates a position between A and B given a ratio number

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Interpolate")]
    [Category("Math/Interpolate", "Positions")]
    
    [Description("Interpolates a position between A and B given a ratio number")]
    [Image(typeof(IconInterpolate), ColorTheme.Type.Yellow)]
    
    [Keywords("Lerp", "Slerp", "Linear", "Smooth", "Damp", "Step")]
    
    [Serializable]
    public class TypeVector3MathInterpolatePositions : TypeVector3
    {
        [SerializeField] private GetVector3 m_VectorA = new GetVector3();
        [SerializeField] private GetVector3 m_VectorB = new GetVector3();
        
        [SerializeField] private GetNumber m_Ratio = new GetNumber();
        [SerializeField] private EaseMode m_Easing = EaseMode.Linear;
        [SerializeField] private GetBool m_Clamp = new GetBool();

        public override Vector3 GetPreview(GameObject source)
        {
            float ratio = Ease.Get(this.m_Easing, (float) this.m_Ratio.GetPreview(source));
            return Interpolate(this.m_VectorA.GetPreview(source), this.m_VectorB.GetPreview(source), ratio,
                this.m_Clamp.GetPreview(source));
        }

        public override Vector3 Get(Args args)
        {
            Vector3 a = this.m_VectorA.Get(args);
            Vector3 b = this.m_VectorB.Get(args);
            
            double ratio = Ease.Get(this.m_Easing, (float) this.m_Ratio.Get(args));
            bool clamp = this.m_Clamp.Get(args);
            
            return Interpolate(a, b, ratio, clamp);
        }

        private static Vector3 Interpolate(Vector3 a, Vector3 b, double ratio, bool clamp)
        {
            if (clamp) ratio = Math.Clamp(ratio, 0.0, 1.0);
            return new Vector3(
                (float) (a.x + (b.x - a.x) * ratio),
                (float) (a.y + (b.y - a.y) * ratio),
                (float) (a.z + (b.z - a.z) * ratio)
            );
        }

        public override string ToString()
        {
            return $"Interpolate {this.m_VectorA} to {this.m_VectorB} by {this.m_Ratio}";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.