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 TypeVector3MathClampMagnitude : TypeVector3
{
[SerializeField] private GetVector3 m_Vector = new GetVector3();
[SerializeField] private GetNumber m_MaxLength = new GetNumber();
public override Vector3 Get(Args args)
{
Vector3 value = Vector3.ClampMagnitude(
m_Vector.Get(args),
(float) m_MaxLength.Get(args)
);
return value;
}
public override string ToString()
{
return $"Clamp {this.m_Vector} to {this.m_MaxLength}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}