Added moveToward for vectors.
This commit is contained in:
parent
f25c3c7a5d
commit
388bea9205
2 changed files with 24 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue