NanosMath
A table containing useful and aux Math functions
๐ Examplesโ
local axis = NanosMath.ClampAxis(720)
local my_value = 0
Client.Subscribe("Tick", function(delta_time)
my_value = NanosMath.FInterpTo(my_value, 100, delta_time, 3)
end)
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: float | Rounds a number to the nearest value with the given decimal places | |
Clamp: float | Clamps a number | |
ClampAxis: float | Clamps an angle to the range of [0, 360] | |
NormalizeAxis: float | Clamps an angle to the range of [-180, 180] | |
RelativeTo: Vector, Rotator | Calculates the location and rotation relative to an actor | |
LocalToWorld: Vector, Rotator | Converts a local location and rotation to world coordinates based on an actor's transform | |
RandomFloat: float | Returns a random float value | |
FInterpTo: float | Interpolate number from Current to Target | |
RInterpTo: Rotator | Interpolate Rotator from Current to Target | |
RInterpConstantTo: Rotator | Interpolate Rotator from Current to Target with a constant step | |
VInterpTo: Vector | Interpolate Vector from Current to Target | |
VInterpConstantTo: Vector | Interpolate 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
| Name | Type | Description |
|---|---|---|
value | float | The number to be rounded |
decimals? | integer | How many decimal places to keep Default 0 |
Returns
| Type | Description |
|---|---|
| float | the rounded number |
ClampOptimalโ
Clamps a number
local ret = NanosMath.Clamp(value, min, max)
Parameters
| Name | Type | Description |
|---|---|---|
value | float | The number to be clamped |
min | float | The min value |
max | float | The max value |
Returns
| Type | Description |
|---|---|
| float | the number clamped |
ClampAxisOptimalโ
Clamps an angle to the range of [0, 360]
local ret = NanosMath.ClampAxis(value)
Parameters
| Name | Type | Description |
|---|---|---|
value | float | The number to be clamped |
Returns
| Type | Description |
|---|---|
| float | the number clamped |
Examples (1)
local axis = NanosMath.ClampAxis(720)
NormalizeAxisOptimalโ
Clamps an angle to the range of [-180, 180]
local ret = NanosMath.NormalizeAxis(value)
Parameters
| Name | Type | Description |
|---|---|---|
value | float | The number to be clamped |
Returns
| Type | Description |
|---|---|
| float | the number clamped |
RelativeToOptimalโ
Calculates the location and rotation relative to an actor
local relative_location, relative_rotation = NanosMath.RelativeTo(location, rotation, actor)
Parameters
| Name | Type | Description |
|---|---|---|
location | Vector | The location of the new system |
rotation | Rotator | The rotation of the new system |
actor | Base Actor | The actor to be translated to the new system |
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
| Name | Type | Description |
|---|---|---|
local_location | Vector | The local location to convert |
local_rotation | Rotator | The local rotation to convert |
actor | Base Actor | The actor whose transform defines the local space |
RandomFloatOptimalโ
Returns a random float value
local ret = NanosMath.RandomFloat(min, max)
Returns
| Type | Description |
|---|---|
| float | the random value |
FInterpToOptimalโ
Interpolate number from Current to Target
local ret = NanosMath.FInterpTo(current, target, delta_time, interp_speed)
Parameters
| Name | Type | Description |
|---|---|---|
current | float | The current value |
target | float | The target value |
delta_time | float | Time since the last call, usually the Tick delta time |
interp_speed | float | Interpolation speed, 0 jumps straight to the target |
Returns
| Type | Description |
|---|---|
| float | The interpolated value |
Examples (1)
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
| Name | Type | Description |
|---|---|---|
current | Rotator | The current value |
target | Rotator | The target value |
delta_time | float | Time since the last call, usually the Tick delta time |
interp_speed | float | Interpolation speed, 0 jumps straight to the target |
Returns
| Type | Description |
|---|---|
| Rotator | The interpolated Rotator |
RInterpConstantToOptimalโ
Interpolate Rotator from Current to Target with a constant step
local ret = NanosMath.RInterpConstantTo(current, target, delta_time, interp_speed)
Parameters
| Name | Type | Description |
|---|---|---|
current | Rotator | The current value |
target | Rotator | The target value |
delta_time | float | Time since the last call, usually the Tick delta time |
interp_speed | float | Interpolation speed, 0 jumps straight to the target |
Returns
| Type | Description |
|---|---|
| Rotator | The interpolated Rotator |
VInterpToOptimalโ
Interpolate Vector from Current to Target
local ret = NanosMath.VInterpTo(current, target, delta_time, interp_speed)
Parameters
| Name | Type | Description |
|---|---|---|
current | Vector | The current value |
target | Vector | The target value |
delta_time | float | Time since the last call, usually the Tick delta time |
interp_speed | float | Interpolation speed, 0 jumps straight to the target |
Returns
| Type | Description |
|---|---|
| Vector | The interpolated Vector |
Examples (1)
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
| Name | Type | Description |
|---|---|---|
current | Vector | The current value |
target | Vector | The target value |
delta_time | float | Time since the last call, usually the Tick delta time |
interp_speed | float | Interpolation speed, 0 jumps straight to the target |
Returns
| Type | Description |
|---|---|
| Vector | The interpolated Vector |
