diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-01 12:05:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 12:05:18 +0200 |
commit | 3c4fab295b96c9bd852601531bf35c1ade56b54c (patch) | |
tree | 9adcec083a49ca4935ff70e1257bd492ca88df62 /core/math/vector3.cpp | |
parent | 64a88e8ef35d692f31d6114793468623c6756785 (diff) | |
parent | c00427add34f505cff275ea33423f1053423d646 (diff) | |
download | redot-engine-3c4fab295b96c9bd852601531bf35c1ade56b54c.tar.gz |
Merge pull request #27789 from Giacom/move_towards
Added move_toward functions for float, Vector2 and Vector3
Diffstat (limited to 'core/math/vector3.cpp')
-rw-r--r-- | core/math/vector3.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 1c28934422..73927821cf 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -127,6 +127,13 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c return out; } +Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const { + Vector3 v = *this; + Vector3 vd = p_to - v; + real_t len = vd.length(); + return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta; +} + Vector3::operator String() const { return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); |