add lerp function to util and lerp method to vector3

This commit is contained in:
2025-02-14 22:02:19 +03:00
parent a532325cd2
commit a0ba6f9da3
2 changed files with 39 additions and 0 deletions

View File

@ -216,6 +216,25 @@ end
function Vector3:copy()
return Vector3(self)
end
---Returns a new vector as a linear interpolation between self and b.
---@param b vectorlike
---@param t number
---@return Vector3
function Vector3:lerp(b, t)
-- return self:copy()
if not is_weak_vector3(b) then
error("Vector3: b must be a Vector3-like table. Returning copy of self.")
return self:copy()
end
local w = Vector3(b)
return Vector3{
util.lerp(self.x, w.x, t),
util.lerp(self.y, w.y, t),
util.lerp(self.z, w.z, t),
}
end
---- CONSTANTS
Vector3.UP = Vector3(0, 1, 0)