HELIXMath
Overviewโ
HELIXMath is a static utility class that wraps common math functions from Unreal Engine's UKismetMathLibrary. It includes helpers for clamping, interpolation, vector math, angle conversions, transforms, and more. This makes math-heavy scripting simpler and consistent across Lua and Blueprint.
Basic Mathโ
HELIXMath.Clamp(value, min, max)โ
Clamps a number between a minimum and maximum value
HELIXMath.Clamp(190, 0, 180) -- Returns 180
HELIXMath.Round(value)โ
Rounds a number to the nearest whole integer
HELIXMath.Round(2.7) -- Returns 3
HELIXMath.Sin(radians)โ
Returns the sine of an angle in radians
HELIXMath.Sin(math.pi / 2) -- Returns 1
HELIXMath.Cos(radians)โ
Returns the cosine of an angle in radians
HELIXMath.Cos(0) -- Returns 1
HELIXMath.Tan(radians)โ
Returns the tangent of an angle in radians
HELIXMath.Tan(math.pi / 4) -- Returns 1
HELIXMath.Sqrt(value)โ
Returns the square root of a number
HELIXMath.Sqrt(25) -- Returns 5
HELIXMath.Square(value)โ
Returns the square (value * value) of a number
HELIXMath.Square(4) -- Returns 16
HELIXMath.Sign(value)โ
Returns -1 for negative values, 1 for positive values, and 0 for zero
HELIXMath.Sign(-10) -- Returns -1
HELIXMath.SafeDivide(a, b)โ
Safely divides two numbers. If b is 0, returns 0 instead of an error
HELIXMath.SafeDivide(10, 0) -- Returns 0
Angle Utilitiesโ
HELIXMath.ClampAxis(angle)โ
Clamps an angle to the range [0, 360). Useful for wrapping yaw angles
HELIXMath.ClampAxis(370) -- Returns 10
HELIXMath.NormalizeAxis(angle)โ
Normalizes an angle to the range [-180, 180). Useful for delta comparisons
HELIXMath.NormalizeAxis(190) -- Returns -170
HELIXMath.DegreesToRadians(degrees)โ
Converts degrees to radians
HELIXMath.DegreesToRadians(180) -- Returns 3.14159
HELIXMath.RadiansToDegrees(radians)โ
Converts radians to degrees
HELIXMath.RadiansToDegrees(math.pi) -- Returns 180
Interpolation & Lerpโ
HELIXMath.FInterpTo(current, target, deltaTime, interpSpeed)โ
Smoothly interpolates between two float values using exponential smoothing
HELIXMath.FInterpTo(0, 100, 0.016, 5) -- Returns something like 1.25
HELIXMath.RInterpTo(current, target, deltaTime, interpSpeed)โ
Interpolates between two rotators over time
HELIXMath.RInterpTo(Rotator(0,0,0), Rotator(0,90,0), 0.016, 5)
HELIXMath.RInterpConstantTo(current, target, deltaTime, interpSpeed)โ
Interpolates between two rotators at a constant rate
HELIXMath.RInterpConstantTo(Rotator(0,0,0), Rotator(0,90,0), 0.016, 45)
HELIXMath.VInterpTo(current, target, deltaTime, interpSpeed)โ
Smoothly interpolates between two vectors
HELIXMath.VInterpTo(Vector(0,0,0), Vector(100,0,0), 0.016, 5)
HELIXMath.VInterpConstantTo(current, target, deltaTime, interpSpeed)โ
Interpolates between two vectors at a constant rate
HELIXMath.VInterpConstantTo(Vector(0,0,0), Vector(100,0,0), 0.016, 200)
HELIXMath.RLerp(A, B, alpha, shortestPath)โ
Performs linear interpolation between two rotators
HELIXMath.RLerp(Rotator(0,0,0), Rotator(0,90,0), 0.5, true)
HELIXMath.VLerp(A, B, alpha)โ
Linearly interpolates between two vectors
HELIXMath.VLerp(Vector(0,0,0), Vector(100,0,0), 0.5) -- Returns Vector(50,0,0)
HELIXMath.TLerp(A, B, alpha)โ
Linearly interpolates between two transforms
HELIXMath.TLerp(TransformA, TransformB, 0.5)
Vector Mathโ
HELIXMath.VectorLength(vec)โ
Returns the length (magnitude) of a vector
HELIXMath.VectorLength(Vector(3, 4, 0)) -- Returns 5
HELIXMath.VectorDistance(vecA, vecB)โ
Returns the distance between two vectors
HELIXMath.VectorDistance(Vector(0, 0, 0), Vector(0, 0, 10)) -- Returns 10
HELIXMath.VectorDistance2D(vecA, vecB)โ
Returns the distance between two vectors on the XY plane
HELIXMath.VectorDistance2D(Vector(0, 0, 0), Vector(3, 4, 5)) -- Returns 5
HELIXMath.VectorNormalize(vec)โ
Returns the normalized (unit) vector in the same direction
HELIXMath.VectorNormalize(Vector(3, 0, 0)) -- Returns Vector(1, 0, 0)
HELIXMath.VectorLerp(vecA, vecB, alpha)โ
Performs linear interpolation between two vectors
HELIXMath.VectorLerp(Vector(0, 0, 0), Vector(10, 0, 0), 0.5) -- Returns Vector(5, 0, 0)
HELIXMath.VectorClampSize(vec, maxSize)โ
Limits a vector's length to a maximum size, preserving direction
HELIXMath.VectorClampSize(Vector(100, 0, 0), 50) -- Returns Vector(50, 0, 0)
HELIXMath.ProjectVectorOnToVector(vec, target)โ
Projects one vector onto another
HELIXMath.ProjectVectorOnToVector(Vector(10, 0, 0), Vector(1, 1, 0))
HELIXMath.ProjectVectorOnToPlane(vec, planeNormal)โ
Projects a vector onto a plane defined by a normal
HELIXMath.ProjectVectorOnToPlane(Vector(1, 1, 1), Vector(0, 0, 1))
HELIXMath.MirrorVectorByNormal(vec, normal)โ
Reflects a vector off a plane defined by a normal
HELIXMath.MirrorVectorByNormal(Vector(1, -1, 0), Vector(0, 1, 0)) -- Returns Vector(1, 1, 0)
Rotator Utilitiesโ
HELIXMath.RotatorFromAxisAndAngle(axis, angle)โ
Creates a rotator from a direction vector and angle in degrees
HELIXMath.RotatorFromAxisAndAngle(Vector(0, 0, 1), 90)
HELIXMath.NormalizeDeltaRotator(rotatorA, rotatorB)โ
Returns the normalized difference between two rotators
HELIXMath.NormalizeDeltaRotator(Rotator(0, 350, 0), Rotator(0, 10, 0)) -- Returns Rotator(0, 20, 0)
Transform Helpersโ
HELIXMath.TransformLocation(transform, location)โ
Transforms a local position to world space using a given transform
HELIXMath.TransformLocation(actor:GetTransform(), Vector(100, 0, 0))
HELIXMath.TransformRotation(transform, rotator)โ
Applies a transformโs rotation to a local rotator
HELIXMath.TransformRotation(actor:GetTransform(), Rotator(0, 90, 0))
HELIXMath.TransformDirection(transform, direction)โ
Transforms a local direction vector into world space using the transform's rotation
HELIXMath.TransformDirection(actor:GetTransform(), Vector(1, 0, 0))
Range Utilitiesโ
HELIXMath.NormalizeToRange(value, rangeMin, rangeMax)โ
Normalizes a value between 0 and 1 based on a specified range
HELIXMath.NormalizeToRange(75, 50, 100) -- Returns 0.5
HELIXMath.Wrap(value, min, max)โ
Wraps a value to stay within a specified range, looping around when necessary
HELIXMath.Wrap(370, 0, 360) -- Returns 10