Is there a moveTowards for float3?

There is Vector3.MoveTowards(…), Is there something similar in new Mathematics? All I see is math.lerp(…).

Thanks!

I believe you can implement your own static method to do this:

public static class float3Extensions
{
    public static float3 MoveTowards(float3 current, float3 target, float maxDistanceDelta)
    {
        float deltaX = target.x - current.x;
        float deltaY = target.y - current.y;
        float deltaZ = target.z - current.z;

        float sqdist = deltaX * deltaX + deltaY * deltaY  + deltaZ * deltaZ ;

        if (sqdist == 0 || sqdist <= maxDistanceDelta * maxDistanceDelta)
            return target;
        var dist = (float)Math.Sqrt(sqdist);

        return new float3(current.x + deltaX / dist * maxDistanceDelta,
            current.y + deltaY / dist * maxDistanceDelta,
            current.z + deltaZ / dist * maxDistanceDelta);
    }
}

Otherwise, you can create an extension method to get a float3 from a Vector3 so you don’t have to handle the implementation of MoveTowards (and every other Vector3 functions) yourself:

 public static class float3Extensions
 {
    public static float3 ToFloat3(this Vector3 input)
    {
        return new float3( input.x, input.y, input.z  );
    }
 }

float3 output = Vector3.MoveTowards( origin, target, delta ).ToFloat3();