Direction From To#
Math / Direction From To
Can Read
Cannot Write
Description#
The unit length direction that goes from one position to another one
Parameters#
| Name | Description |
|---|---|
| From | The position the direction starts at |
| To | The position the direction points to |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Direction From To")]
[Category("Math/Direction From To")]
[Description("The unit length direction that goes from one position to another one")]
[Image(typeof(IconCompass), ColorTheme.Type.Yellow, typeof(BadgeArrowRight))]
[Parameter("From", "The position the direction starts at")]
[Parameter("To", "The position the direction points to")]
[Keywords("Vector", "Towards", "Look", "Aim", "Normalize", "Subtract", "Delta")]
[Serializable]
public class TypeVector3MathDirectionFromTo : TypeVector3
{
[SerializeField] private GetVector3 m_From = new GetVector3();
[SerializeField] private GetVector3 m_To = new GetVector3();
public override Vector3 GetPreview(GameObject source) => Direction(
this.m_From.GetPreview(source),
this.m_To.GetPreview(source)
);
public override Vector3 Get(Args args) => Direction(this.m_From.Get(args), this.m_To.Get(args));
private static Vector3 Direction(Vector3 from, Vector3 to)
{
return (to - from).normalized;
}
public override string ToString()
{
return $"{this.m_From} to {this.m_To}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}