--// Vector --// Written by Demo (R0BL0XIAN_D3M0) --// [https://www.roblox.com/users/289025524/profile] --// 11/09/2023 type TVector = Vector2 | Vector3 local Vector = {} function Vector.FromVector2XY(vector: Vector2) return (Vector3.new(vector.X, vector.Y, 0)) end function Vector.FromVector2XZ(vector: Vector2) return (Vector3.new(vector.X, 0, vector.Y)) end function Vector.RetrieveAngleRadian(vector: Vector2, _vector: Vector2) if vector.Magnitude == 0 then return nil end return (math.acos(vector:Dot(_vector))) end function Vector.AngleBetweenVectors(vector: Vector2, _vector: Vector2) local newVector: Vector2 = (_vector.Magnitude * vector) local _newVector: Vector2 = (vector.Magnitude * _vector) return (2 * (math.atan2((_newVector - newVector).Magnitude, (newVector + _newVector).Magnitude))) end function Vector.Round(vector: Vector3, amount: number) return ( Vector3.new( ((math.round(vector.X / amount)) * amount), ((math.round(vector.Y / amount)) * amount), ((math.round(vector.Z / amount)) * amount) ) ) end function Vector.ClampMagnitude(vector: TVector, maxMagnitude: number) return ((vector.Magnitude > maxMagnitude) and (vector.Unit * maxMagnitude) or vector) end function Vector.AngleBetween(vector: TVector, _vector: TVector) return (math.acos(math.clamp(vector.Unit:Dot(_vector.Unit), -1, 1))) end function Vector.AngleBetweenSigned(vector: TVector, _vector: TVector, axisVector: TVector) local angle: number = Vector.AngleBetween(vector, _vector) return (angle * (math.sign(axisVector:Dot(vector:Cross(_vector))))) end function Vector.RetrieveRandomUnitVector() local randomX: number = (2 * ((math.random()) - 0.5)) local randomY: number = (6.2831853071796 * (math.random())) local randomZ: number = ((1 - (randomX * randomX)) ^ 0.5) local X: number = randomX local Y: number = (randomZ * (math.cos(randomZ))) local Z: number = (randomZ * (math.sin(randomY))) return (Vector3.new(X, Y, Z)) end return Vector