1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Added move_toward functions for float, Vector2 and Vector3

This commit is contained in:
Giacom
2019-04-07 22:40:56 +01:00
parent 252c841d7f
commit c00427add3
24 changed files with 205 additions and 36 deletions

View File

@@ -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));