diff --git a/src/KingSystem/System/VFR.h b/src/KingSystem/System/VFR.h index 945072ce..a664c2c1 100644 --- a/src/KingSystem/System/VFR.h +++ b/src/KingSystem/System/VFR.h @@ -130,6 +130,21 @@ public: return false; } + template + static inline bool chaseVec(VectorT* value, const VectorT& target, f32 t) { + const auto delta = instance()->getDeltaTime() * t; + const auto diff = target - *value; + const auto norm = diff.length(); + + if (norm <= delta) { + value->e = target.e; + return true; + } + + value->setScaleAdd(delta, (1.0f / norm) * diff, *value); + return false; + } + private: struct TimeSpeedMultipliers : sead::Buffer { TimeSpeedMultipliers() { diff --git a/src/KingSystem/System/VFRValue.cpp b/src/KingSystem/System/VFRValue.cpp index f8452a72..aa9328b2 100644 --- a/src/KingSystem/System/VFRValue.cpp +++ b/src/KingSystem/System/VFRValue.cpp @@ -71,17 +71,7 @@ void VFRVec3f::lerp(const sead::Vector3f& b, f32 t) { } bool VFRVec3f::chase(const sead::Vector3f& target, f32 t) { - const auto delta = VFR::instance()->getDeltaTime() * t; - const auto diff = target - value; - const auto norm = diff.length(); - - if (norm <= delta) { - sead::MemUtil::copy(&value, &target, sizeof(value)); - return true; - } - - value += diff * (1.0f / norm) * delta; - return false; + return VFR::chaseVec(&value, target, t); } void VFRValue::setToMax(const f32& max) {