summaryrefslogtreecommitdiff
path: root/core/math/vector2.cpp
diff options
context:
space:
mode:
authorGiacom <giacomand@gmail.com>2019-04-07 22:40:56 +0100
committerGiacom <giacomand@gmail.com>2019-05-28 11:39:35 +0100
commitc00427add34f505cff275ea33423f1053423d646 (patch)
tree9fef14ccadd219e7050de28394a53e72209268ce /core/math/vector2.cpp
parent252c841d7ff5d770e8d2819e4f7955363410744b (diff)
Added move_toward functions for float, Vector2 and Vector3
Diffstat (limited to 'core/math/vector2.cpp')
-rw-r--r--core/math/vector2.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 5c1ea5943d..779a28be66 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -164,6 +164,13 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
return out;
}
+Vector2 Vector2::move_toward(const Vector2 &p_to, const real_t p_delta) const {
+ Vector2 v = *this;
+ Vector2 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+}
+
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2 Vector2::slide(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS