Skip to main content
Version: latest - a1.142.x ⚖️

NanosMath

A table containing useful and aux Math functions.

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
👐Open Source
This library implementation is Open Sourced on GitHub!
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

🎒 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

ReturnsNameDescription
numberRoundRounds a number
numberClampClamps a number
numberClampAxisClamps an angle to the range of [0, 360]
numberNormalizeAxisClamps an angle to the range of [-180, 180]
Vector, RotatorRelativeToCalculates the location and rotation relative to an actor
Vector, RotatorLocalToWorldConverts a local location and rotation to world coordinates based on an actor's transform
floatRandomFloatReturns a random float value
numberFInterpToInterpolate number from Current to Target
RotatorRInterpToInterpolate Rotator from Current to Target
RotatorRInterpConstantToInterpolate Rotator from Current to Target with a constant step
VectorVInterpToInterpolate Vector from Current to Target
VectorVInterpConstantToInterpolate Vector from Current to Target with a constant step

Round

Rounds a number
local ret = NanosMath.Round(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter The number to be rounded

Returns

TypeDescription
numberthe rounded number

Clamp

Clamps a number
local ret = NanosMath.Clamp(value, min, max)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter The number to be clamped
numbermin Required parameter The min value
numbermax Required parameter The max value

Returns

TypeDescription
numberthe number clamped

ClampAxis

Clamps an angle to the range of [0, 360]
local ret = NanosMath.ClampAxis(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter The number to be clamped

Returns

TypeDescription
numberthe number clamped
NanosMath.ClampAxis Examples
Clamping an angle
local axis = NanosMath.ClampAxis(720)

NormalizeAxis

Clamps an angle to the range of [-180, 180]
local ret = NanosMath.NormalizeAxis(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter The number to be clamped

Returns

TypeDescription
numberthe number clamped

RelativeTo

Calculates the location and rotation relative to an actor
local ret_1, ret_2 = NanosMath.RelativeTo(location, rotation, actor)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter The location of the new system
Rotatorrotation Required parameter The rotation of the new system
Base Actoractor Required parameter The actor to be translated to the new system

Returns

TypeDescription
Vectorthe location relative to the actor
Rotatorthe rotation relative to the actor

LocalToWorld

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 ret_1, ret_2 = NanosMath.LocalToWorld(local_location, local_rotation, actor)

Parameters

TypeParameterDefaultDescription
Vectorlocal_location Required parameter The local location to convert
Rotatorlocal_rotation Required parameter The local rotation to convert
Base Actoractor Required parameter The actor whose transform defines the local space

Returns

TypeDescription
Vectorthe location in world coordinates
Rotatorthe rotation in world coordinates

RandomFloat

Returns a random float value
local ret = NanosMath.RandomFloat(min, max)

Parameters

TypeParameterDefaultDescription
floatmin Required parameter Minimum value
floatmax Required parameter Maximum value

Returns

TypeDescription
floatthe random value

FInterpTo

Interpolate number from Current to Target
local ret = NanosMath.FInterpTo(current, target, delta_time, interp_speed)

Parameters

TypeParameterDefaultDescription
numbercurrent Required parameter No description provided
numbertarget Required parameter No description provided
numberdelta_time Required parameter No description provided
numberinterp_speed Required parameter No description provided

Returns

TypeDescription
numberNo description provided
NanosMath.FInterpTo Examples
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)

RInterpTo

Interpolate Rotator from Current to Target
local ret = NanosMath.RInterpTo(current, target, delta_time, interp_speed)

Parameters

TypeParameterDefaultDescription
Rotatorcurrent Required parameter No description provided
Rotatortarget Required parameter No description provided
numberdelta_time Required parameter No description provided
numberinterp_speed Required parameter No description provided

Returns

TypeDescription
RotatorNo description provided

RInterpConstantTo

Interpolate Rotator from Current to Target with a constant step
local ret = NanosMath.RInterpConstantTo(current, target, delta_time, interp_speed)

Parameters

TypeParameterDefaultDescription
Rotatorcurrent Required parameter No description provided
Rotatortarget Required parameter No description provided
numberdelta_time Required parameter No description provided
numberinterp_speed Required parameter No description provided

Returns

TypeDescription
RotatorNo description provided

VInterpTo

Interpolate Vector from Current to Target
local ret = NanosMath.VInterpTo(current, target, delta_time, interp_speed)

Parameters

TypeParameterDefaultDescription
Vectorcurrent Required parameter No description provided
Vectortarget Required parameter No description provided
numberdelta_time Required parameter No description provided
numberinterp_speed Required parameter No description provided

Returns

TypeDescription
VectorNo description provided
NanosMath.VInterpTo Examples
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)

VInterpConstantTo

Interpolate Vector from Current to Target with a constant step
local ret = NanosMath.VInterpConstantTo(current, target, delta_time, interp_speed)

Parameters

TypeParameterDefaultDescription
Vectorcurrent Required parameter No description provided
Vectortarget Required parameter No description provided
numberdelta_time Required parameter No description provided
numberinterp_speed Required parameter No description provided

Returns

TypeDescription
VectorNo description provided