Move Towards#
Math / Move Towards
Can Read
Cannot Write
Description#
Moves from one position to another, but no farther than a delta distance
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Move Towards")]
[Category("Math/Move Towards")]
[Description("Moves from one position to another, but no farther than a delta distance")]
[Image(typeof(IconPosition), ColorTheme.Type.Yellow, typeof(BadgeArrowRight))]
[Keywords("Vector", "Translate")]
[Serializable]
public class TypeVector3MathMoveTowards : TypeVector3
{
[SerializeField] private GetVector3 m_Current = new GetVector3();
[SerializeField] private GetVector3 m_Target = new GetVector3();
[SerializeField] private GetNumber m_MaxDistanceDelta = new GetNumber();
public override Vector3 Get(Args args)
{
return Vector3.MoveTowards(
this.m_Current.Get(args),
this.m_Target.Get(args),
(float) this.m_MaxDistanceDelta.Get(args)
);
}
public override string ToString()
{
return $"Move from {this.m_Current} towards {this.m_Target}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}