Skip to main content
Version: bleeding-edge ๐Ÿฉธ

NanosMath

A table containing useful and aux Math functions


๐ŸŽ’ Examplesโ€‹

(NanosMath.ClampAxis) Clamping an angle
local axis = NanosMath.ClampAxis(720)
(NanosMath.FInterpTo) Interpolating a number until it reaches 100 with speed 3
local my_value = 0
Client.Subscribe("Tick", function(delta_time)
my_value = NanosMath.FInterpTo(my_value, 100, delta_time, 3)
end)
(NanosMath.VInterpTo) Interpolating a Vector until it reaches Vector(1000, 200, 100) with speed 5
local my_value = Vector(0, 0, 0)
Client.Subscribe("Tick", function(delta_time)
my_value = NanosMath.VInterpTo(my_value, Vector(1000, 200, 100), delta_time, 5)
end)

๐Ÿ—ฟ Static Functionsโ€‹

Round: floatRounds a number to the nearest value with the given decimal places
Clamp: floatClamps a number
ClampAxis: floatClamps an angle to the range of [0, 360]
NormalizeAxis: floatClamps an angle to the range of [-180, 180]
RelativeTo: Vector, RotatorCalculates the location and rotation relative to an actor
LocalToWorld: Vector, RotatorConverts a local location and rotation to world coordinates based on an actor's transform
RandomFloat: floatReturns a random float value
FInterpTo: floatInterpolate number from Current to Target
RInterpTo: RotatorInterpolate Rotator from Current to Target
RInterpConstantTo: RotatorInterpolate Rotator from Current to Target with a constant step
VInterpTo: VectorInterpolate Vector from Current to Target
VInterpConstantTo: VectorInterpolate Vector from Current to Target with a constant step

RoundOptimalโ€‹

Rounds a number to the nearest value with the given decimal places

local ret = NanosMath.Round(value, decimals?)
Parameters
NameTypeDescription
valuefloatThe number to be rounded
decimals?integerHow many decimal places to keep Default 0
Returns
TypeDescription
floatthe rounded number

ClampOptimalโ€‹

Clamps a number

local ret = NanosMath.Clamp(value, min, max)
Parameters
NameTypeDescription
valuefloatThe number to be clamped
minfloatThe min value
maxfloatThe max value
Returns
TypeDescription
floatthe number clamped

ClampAxisOptimalโ€‹

Clamps an angle to the range of [0, 360]

local ret = NanosMath.ClampAxis(value)
Parameters
NameTypeDescription
valuefloatThe number to be clamped
Returns
TypeDescription
floatthe number clamped
Examples (1)
Clamping an angle
local axis = NanosMath.ClampAxis(720)

NormalizeAxisOptimalโ€‹

Clamps an angle to the range of [-180, 180]

local ret = NanosMath.NormalizeAxis(value)
Parameters
NameTypeDescription
valuefloatThe number to be clamped
Returns
TypeDescription
floatthe number clamped

RelativeToOptimalโ€‹

Calculates the location and rotation relative to an actor

local relative_location, relative_rotation = NanosMath.RelativeTo(location, rotation, actor)
Parameters
NameTypeDescription
locationVectorThe location of the new system
rotationRotatorThe rotation of the new system
actorBase ActorThe actor to be translated to the new system
Returns
TypeDescription
Vectorthe location relative to the actor
Rotatorthe rotation relative to the actor

LocalToWorldOptimalโ€‹

Converts a local location and rotation to world coordinates based on an actor's transform

Takes a local position and rotation relative to an actor, applies the actor's location, rotation, and scale to compute world-space location and rotation

local world_location, world_rotation = NanosMath.LocalToWorld(local_location, local_rotation, actor)
Parameters
NameTypeDescription
local_locationVectorThe local location to convert
local_rotationRotatorThe local rotation to convert
actorBase ActorThe actor whose transform defines the local space
Returns
TypeDescription
Vectorthe location in world coordinates
Rotatorthe rotation in world coordinates

RandomFloatOptimalโ€‹

Returns a random float value

local ret = NanosMath.RandomFloat(min, max)
Parameters
NameTypeDescription
minfloatMinimum value
maxfloatMaximum value
Returns
TypeDescription
floatthe random value

FInterpToOptimalโ€‹

Interpolate number from Current to Target

local ret = NanosMath.FInterpTo(current, target, delta_time, interp_speed)
Parameters
NameTypeDescription
currentfloatThe current value
targetfloatThe target value
delta_timefloatTime since the last call, usually the Tick delta time
interp_speedfloatInterpolation speed, 0 jumps straight to the target
Returns
TypeDescription
floatThe interpolated value
Examples (1)
Interpolating a number until it reaches 100 with speed 3
local my_value = 0
Client.Subscribe("Tick", function(delta_time)
my_value = NanosMath.FInterpTo(my_value, 100, delta_time, 3)
end)

RInterpToOptimalโ€‹

Interpolate Rotator from Current to Target

local ret = NanosMath.RInterpTo(current, target, delta_time, interp_speed)
Parameters
NameTypeDescription
currentRotatorThe current value
targetRotatorThe target value
delta_timefloatTime since the last call, usually the Tick delta time
interp_speedfloatInterpolation speed, 0 jumps straight to the target
Returns
TypeDescription
RotatorThe interpolated Rotator

RInterpConstantToOptimalโ€‹

Interpolate Rotator from Current to Target with a constant step

local ret = NanosMath.RInterpConstantTo(current, target, delta_time, interp_speed)
Parameters
NameTypeDescription
currentRotatorThe current value
targetRotatorThe target value
delta_timefloatTime since the last call, usually the Tick delta time
interp_speedfloatInterpolation speed, 0 jumps straight to the target
Returns
TypeDescription
RotatorThe interpolated Rotator

VInterpToOptimalโ€‹

Interpolate Vector from Current to Target

local ret = NanosMath.VInterpTo(current, target, delta_time, interp_speed)
Parameters
NameTypeDescription
currentVectorThe current value
targetVectorThe target value
delta_timefloatTime since the last call, usually the Tick delta time
interp_speedfloatInterpolation speed, 0 jumps straight to the target
Returns
TypeDescription
VectorThe interpolated Vector
Examples (1)
Interpolating a Vector until it reaches Vector(1000, 200, 100) with speed 5
local my_value = Vector(0, 0, 0)
Client.Subscribe("Tick", function(delta_time)
my_value = NanosMath.VInterpTo(my_value, Vector(1000, 200, 100), delta_time, 5)
end)

VInterpConstantToOptimalโ€‹

Interpolate Vector from Current to Target with a constant step

local ret = NanosMath.VInterpConstantTo(current, target, delta_time, interp_speed)
Parameters
NameTypeDescription
currentVectorThe current value
targetVectorThe target value
delta_timefloatTime since the last call, usually the Tick delta time
interp_speedfloatInterpolation speed, 0 jumps straight to the target
Returns
TypeDescription
VectorThe interpolated Vector