Feel free to submit a pull request with your own contributions!
- AngleBetween.lua
- GammaColorTransition.lua
- LinearInterpolation.lua
- Map.lua
- ModelCFramer.lua
- Reflection.lua
- RoundNumbers.lua
-- Find angle between two vectors:
local function AngleBetween(vectorA, vectorB)
return math.acos(math.clamp(vectorA.Unit:Dot(vectorB.Unit), -1, 1))
end-- Allows for linear interpolation between two colors using a specified Gamma value.
-- Utility function to apply a power to Color3
local function PowColor3(color, pow)
return Color3.new(math.pow(color.R, pow), math.pow(color.G, pow), math.pow(color.B, pow))
end
-- Interpolate between 'ColorA' and 'ColorB' by 'Frac' percentage with an optional 'Gamma' value.
-- Typical gamma values range from 1.8 to 2.2. The default value is 2.0.
local function LerpColor(colorA, colorB, frac, gamma)
gamma = (gamma or 2.0)
local ca = PowColor3(colorA, gamma)
local cb = PowColor3(colorB, gamma)
return PowColor3(ca:Lerp(cb, frac), 1 / gamma)
end
-- Linear Interpolation (AKA Lerp)
-- Interpolate between 'a' and 'b' by 'x' percentage
local function Lerp(a, b, x)
return a + ((b - a) * x)
end-- Remap 'n' from the old range (oldMin, oldMax) to the new range (min, max)
local function Map(n, oldMin, oldMax, min, max)
return (min + ((max - min) * ((n - oldMin) / (oldMax - oldMin))))
end-- SetPrimaryPartCFrame but avoids float errors via caching
-- ExampleSetterFunction = ModelCFramer(workspace.Model)
-- ExampleSetterFunction(CFrame.new(0, 5, 0))
local function ModelCFramer(model)
local primary = model.PrimaryPart
local primaryCf = primary.CFrame
local cache = {}
for _,child in ipairs(model:GetDescendants()) do
if (child:IsA("BasePart") and child ~= primary) then
cache[child] = primaryCf:ToObjectSpace(child.CFrame)
end
end
return function(desiredCf)
primary.CFrame = desiredCf
for part,offset in pairs(cache) do
part.CFrame = desiredCf * offset
end
end
end
-- Finding the reflection vector for an incident vector
-- Arguments made for raycast [Origin, RaycastResult.Position, RaycastResult.Normal]
local function Reflection(origin : Vector3,hitpos : Vector3,normal : Vector3)
return ((hitpos - origin) - 2*((hitpos - origin):Dot(normal) * normal))
end-- Round 'x' to the nearest 'mult'
local function Round(x, mult)
return math.round(x / mult) * mult
end