Added moveToward for vectors.

This commit is contained in:
Arun Dilipan 2020-11-23 11:29:03 -05:00 • committed by Ruslan Mustakov
commit 388bea9205
2 changed files with 24 additions and 0 deletions

View file

@ -5,6 +5,8 @@ import math, godotbase, hashes
import internal/godotinternaltypes, internal/godotstrings
import godotcoretypes, gdnativeapi
const EPSILON = 0.00001'f32
{.push stackTrace: off.}
proc vec2*(): Vector2 {.inline, noinit.} =
@ -199,4 +201,14 @@ proc clamped*(self: Vector2; length: float32): Vector2 {.noinit.} =
result /= len
result *= length
proc moveToward*(vFrom, to: Vector2, delta: float32): Vector2 =
let
vd = to - vFrom
vLen = vd.length
if vLen <= delta or vLen < EPSILON:
result = to
else:
result = vFrom + (vd / vLen) * delta
{.pop.} # stackTrace: off