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

Move Towards#

Math / Algebra / Move Towards

  • Can Read

  • Cannot Write

Description#

Moves a number towards another one without ever overshooting it

Parameters#

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

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Move Towards")]
    [Category("Math/Algebra/Move Towards")]

    [Description("Moves a number towards another one without ever overshooting it")]
    [Image(typeof(IconSpeed), ColorTheme.Type.Yellow)]

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

    [Keywords("Approach", "Step", "Lerp", "Towards", "Clamp")]

    [Serializable]
    public class TypeNumberMathMoveTowards : TypeNumber
    {
        [SerializeField] private GetNumber m_Current = new GetNumber();
        [SerializeField] private GetNumber m_Target = new GetNumber();
        [SerializeField] private GetNumber m_MaxDelta = new GetNumber(1f);

        public override double GetPreview(GameObject source) => Mathf.MoveTowards(
            (float) this.m_Current.GetPreview(source),
            (float) this.m_Target.GetPreview(source),
            (float) this.m_MaxDelta.GetPreview(source)
        );

        public override double Get(Args args)
        {
            return Mathf.MoveTowards(
                this.m_Current.GetFloat(args),
                this.m_Target.GetFloat(args),
                this.m_MaxDelta.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.