diff --git a/changelog/snippets/other.6438.md b/changelog/snippets/other.6438.md index 983cdb4dc4..d9e6646414 100644 --- a/changelog/snippets/other.6438.md +++ b/changelog/snippets/other.6438.md @@ -1,4 +1,4 @@ -- (#5061, #6438, #6527) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. +- (#5061, #6438, #6527, #6525) Add metamethods and utility functions for Vectors and Quaternions to simplify and clean up the code involving operations with them. - This **removes** the file `/lua/shared/quaternions.lua`, which was added in #4768 (Mar 4, 2023), so mods that use that file will have to be updated. - The metamethods (defined globally in `/lua/system/utils.lua`) include: - Vector/Vector2 addition/subtraction/negation diff --git a/lua/utilities.lua b/lua/utilities.lua index 4423c723ed..0b33e22d8e 100644 --- a/lua/utilities.lua +++ b/lua/utilities.lua @@ -406,12 +406,11 @@ end ---@param v2 Vector ---@return number function GetAngleInBetween(v1, v2) - local x1, y1, z2 = v1[1], v1[2], v1[3] + local x1, y1, z1 = v1[1], v1[2], v1[3] local x2, y2, z2 = v2[1], v2[2], v2[3] -- arccos((v1 . v2) / (|v1| |v2|)) - local z2Sq = z2 * z2 - local dot = x1*x2 + y1*y2 + z2Sq - local len2 = MathSqrt((x1*x1 + y1*y1 + z2Sq) * (x2*x2 + y2*y2 + z2Sq)) + local dot = x1 * x2 + y1 * y2 + z1 * z2 + local len2 = MathSqrt((x1 * x1 + y1 * y1 + z1 * z1) * (x2 * x2 + y2 * y2 + z2 * z2)) return MathACos(dot / len2) * 180 / math.pi end