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

Clamp Magnitude#

Math / Clamp Magnitude

  • Can Read

  • Cannot Write

Description#

Returns a vector with its magnitude clamped to maxLength

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Clamp Magnitude")]
    [Category("Math/Clamp Magnitude")]
    [Description("Returns a vector with its magnitude clamped to maxLength")]
    
    [Image(typeof(IconCompass), ColorTheme.Type.Yellow)]
    [Keywords("Vector", "Max")]
    
    [Serializable]
    public class TypeVector2MathClampMagnitude : TypeVector2
    {
        [SerializeField] private GetVector2 m_Vector = new GetVector2();
        [SerializeField] private GetNumber m_MaxLength = new GetNumber();

        public override Vector2 GetPreview(GameObject source) =>
            Vector2.ClampMagnitude(
                this.m_Vector.GetPreview(source),
                (float) this.m_MaxLength.GetPreview(source)
            );

        public override Vector2 Get(Args args)
        {
            return Vector2.ClampMagnitude(
                this.m_Vector.Get(args),
                (float) this.m_MaxLength.Get(args)
            );
        }
        
        public override string ToString()
        {
            return $"Clamp {this.m_Vector} to {this.m_MaxLength}";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.