NanosMath
包含实用及辅助数学函数的表。
🎒 示例
(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)
🗿 静态函数
| Returns | Name | Description | |
|---|---|---|---|
| number | Round | 对数字进行四舍五入 | |
| number | Clamp | 将数字限制在指定范围内 | |
| number | ClampAxis | 将角度限制在 [0, 360] 范围内 | |
| number | NormalizeAxis | 将角度映射到 [-180, 180] 范围内 | |
| Vector, Rotator | RelativeTo | 计算相对于某个 Actor 的位置和旋转 | |
| Vector, Rotator | LocalToWorld | 根据 Actor 的变换信息,将本地位置和旋转转换为世界坐标 | |
| float | RandomFloat | 返回一个随机浮点值 | |
| number | FInterpTo | 将数字从当前值插值到目标值 | |
| Rotator | RInterpTo | 将旋转体从当前值插值到目标值 | |
| Rotator | RInterpConstantTo | 以恒定步长将旋转体从当前值插值到目标值 | |
| Vector | VInterpTo | 将向量从当前值插值到目标值 | |
| Vector | VInterpConstantTo | 以恒定步长将向量从当前值插值到目标值 |
Round
对数字进行四舍五入
local ret = NanosMath.Round(value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | value | Required parameter | 要进行四舍五入的数字 |
Returns
| Type | Description |
|---|---|
| number | 四舍五入后的数字 |
Clamp
将数字限制在指定范围内
local ret = NanosMath.Clamp(value, min, max)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | value | Required parameter | 要限制的数字 |
| number | min | Required parameter | 最小值 |
| number | max | Required parameter | 最大值 |
Returns
| Type | Description |
|---|---|
| number | 限制后的数字 |
ClampAxis
将角度限制在 [0, 360] 范围内
local ret = NanosMath.ClampAxis(value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | value | Required parameter | 要限制的数字 |
Returns
| Type | Description |
|---|---|
| number | 限制后的数字 |
NanosMath.ClampAxis Examples
Clamping an angle
local axis = NanosMath.ClampAxis(720)
NormalizeAxis
将角度映射到 [-180, 180] 范围内
local ret = NanosMath.NormalizeAxis(value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | value | Required parameter | 要限制的数字 |
Returns
| Type | Description |
|---|---|
| number | 限制后的数字 |
RelativeTo
计算相对于某个 Actor 的位置和旋转
local ret_1, ret_2 = NanosMath.RelativeTo(location, rotation, actor)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | location | Required parameter | 新坐标系的位置 |
| Rotator | rotation | Required parameter | 新坐标系的旋转 |
| Base Actor | actor | Required parameter | 要转换到新坐标系中的 Actor |
LocalToWorld
获取相对于某个 Actor 的本地位置和旋转,应用该 Actor 的位置、旋转和缩放,从而计算出世界空间下的位置和旋转。
local ret_1, ret_2 = NanosMath.LocalToWorld(local_location, local_rotation, actor)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | local_location | Required parameter | 要转换的本地位置 |
| Rotator | local_rotation | Required parameter | 要转换的本地旋转 |
| Base Actor | actor | Required parameter | 定义该本地空间的 Actor |
RandomFloat
返回一个随机浮点值
local ret = NanosMath.RandomFloat(min, max)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | min | Required parameter | 最小值 |
| float | max | Required parameter | 最大值 |
Returns
| Type | Description |
|---|---|
| float | 随机值 |
FInterpTo
将数字从当前值插值到目标值
local ret = NanosMath.FInterpTo(current, target, delta_time, interp_speed)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | current | Required parameter | No description provided |
| number | target | Required parameter | No description provided |
| number | delta_time | Required parameter | No description provided |
| number | interp_speed | Required parameter | No description provided |
Returns
| Type | Description |
|---|---|
| number | No 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
将旋转体从当前值插值到目标值
local ret = NanosMath.RInterpTo(current, target, delta_time, interp_speed)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Rotator | current | Required parameter | No description provided |
| Rotator | target | Required parameter | No description provided |
| number | delta_time | Required parameter | No description provided |
| number | interp_speed | Required parameter | No description provided |
Returns
| Type | Description |
|---|---|
| Rotator | No description provided |
RInterpConstantTo
以恒定步长将旋转体从当前值插值到目标值
local ret = NanosMath.RInterpConstantTo(current, target, delta_time, interp_speed)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Rotator | current | Required parameter | No description provided |
| Rotator | target | Required parameter | No description provided |
| number | delta_time | Required parameter | No description provided |
| number | interp_speed | Required parameter | No description provided |
Returns
| Type | Description |
|---|---|
| Rotator | No description provided |
VInterpTo
将向量从当前值插值到目标值
local ret = NanosMath.VInterpTo(current, target, delta_time, interp_speed)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | current | Required parameter | No description provided |
| Vector | target | Required parameter | No description provided |
| number | delta_time | Required parameter | No description provided |
| number | interp_speed | Required parameter | No description provided |
Returns
| Type | Description |
|---|---|
| Vector | No 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
以恒定步长将向量从当前值插值到目标值
local ret = NanosMath.VInterpConstantTo(current, target, delta_time, interp_speed)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | current | Required parameter | No description provided |
| Vector | target | Required parameter | No description provided |
| number | delta_time | Required parameter | No description provided |
| number | interp_speed | Required parameter | No description provided |
Returns
| Type | Description |
|---|---|
| Vector | No description provided |