Skip to content

Commit

Permalink
Fixed Recursivity of float3.movetowards()
Browse files Browse the repository at this point in the history
  • Loading branch information
ltmx committed Aug 27, 2023
1 parent 75295ec commit b979ff2
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions Runtime/mathx.Mathf.translations.movetowards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// ** Repository : https://github.com/LTMX/Unity.mathx
#endregion

using UnityEngine;

namespace Unity.Mathematics
{
public partial class mathx
Expand All @@ -21,27 +19,20 @@ public static float4 movetowards(this float4 current, float4 target, float4 maxD
public static float4 movetowards(this float4 current, float4 target, float maxDistanceDelta)
{
var delta = target - current;
var deltaLength = delta.length();
return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current);
return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current);
}
/// <inheritdoc cref="movetowards(Mathematics.float4,Mathematics.float4,float)"/>
public static float3 movetowards(this float3 current, float3 target, float3 maxDistanceDelta)
{
var delta = target - current;
return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current);
return math.mad(min(abs(delta), maxDistanceDelta), sign(delta),current);
}
/// <inheritdoc cref="movetowards(Mathematics.float4,Mathematics.float4,float)"/>
public static float3 movetowards(this float3 current, float3 target, float maxDistanceDelta)
{
return movetowards(current, target, maxDistanceDelta);
var delta = target - current;
return math.mad(min(abs(delta), maxDistanceDelta),sign(delta),current);
}
// /// <inheritdoc cref="movetowards(Mathematics.float4,Mathematics.float4,float)"/>
// public static float2 movetowards(this float2 current, float2 target, float2 maxDistanceDelta)
// {
// var delta = target - current;
// var deltaLength = delta.length();
// return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current);
// }
/// <inheritdoc cref="movetowards(Mathematics.float4,Mathematics.float4,float)"/>
public static float2 movetowards(this float2 current, float2 target, float2 maxDistanceDelta)
{
Expand All @@ -52,8 +43,7 @@ public static float2 movetowards(this float2 current, float2 target, float2 maxD
public static float2 movetowards(this float2 current, float2 target, float maxDistanceDelta)
{
var delta = target - current;
var deltaLength = delta.length();
return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current);
return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current);
}
/// <inheritdoc cref="movetowards(Mathematics.float4,Mathematics.float4,float)"/>
public static float movetowards(this float current, float target, float maxDistanceDelta)
Expand All @@ -62,6 +52,7 @@ public static float movetowards(this float current, float target, float maxDista
return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current);
}

// For Reference
// float3 MoveTowards(float3 current, float3 target, float maxDistanceDelta)
// {
// float3 delta = target - current;
Expand Down

0 comments on commit b979ff2

Please sign in to comment.