Added move_toward functions for float, Vector2 and Vector3
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user