跳至正文
版本:最新版 - a1.148.0 ⚖️

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)

🗿 静态函数

ReturnsNameDescription
numberRound对数字进行四舍五入
numberClamp将数字限制在指定范围内
numberClampAxis将角度限制在 [0, 360] 范围内
numberNormalizeAxis将角度映射到 [-180, 180] 范围内
Vector, RotatorRelativeTo计算相对于某个 Actor 的位置和旋转
Vector, RotatorLocalToWorld根据 Actor 的变换信息,将本地位置和旋转转换为世界坐标
floatRandomFloat返回一个随机浮点值
numberFInterpTo将数字从当前值插值到目标值
RotatorRInterpTo将旋转体从当前值插值到目标值
RotatorRInterpConstantTo以恒定步长将旋转体从当前值插值到目标值
VectorVInterpTo将向量从当前值插值到目标值
VectorVInterpConstantTo以恒定步长将向量从当前值插值到目标值

Round

对数字进行四舍五入
local ret = NanosMath.Round(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter 要进行四舍五入的数字

Returns

TypeDescription
number四舍五入后的数字

Clamp

将数字限制在指定范围内
local ret = NanosMath.Clamp(value, min, max)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter 要限制的数字
numbermin Required parameter 最小值
numbermax Required parameter 最大值

Returns

TypeDescription
number限制后的数字

ClampAxis

将角度限制在 [0, 360] 范围内
local ret = NanosMath.ClampAxis(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter 要限制的数字

Returns

TypeDescription
number限制后的数字
NanosMath.ClampAxis Examples
Clamping an angle
local axis = NanosMath.ClampAxis(720)

NormalizeAxis

将角度映射到 [-180, 180] 范围内
local ret = NanosMath.NormalizeAxis(value)

Parameters

TypeParameterDefaultDescription
numbervalue Required parameter 要限制的数字

Returns

TypeDescription
number限制后的数字

RelativeTo

计算相对于某个 Actor 的位置和旋转
local ret_1, ret_2 = NanosMath.RelativeTo(location, rotation, actor)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter 新坐标系的位置
Rotatorrotation Required parameter 新坐标系的旋转
Base Actoractor Required parameter 要转换到新坐标系中的 Actor

Returns

TypeDescription
Vector相对于该 Actor 的位置
Rotator相对于该 Actor 的旋转

LocalToWorld

获取相对于某个 Actor 的本地位置和旋转,应用该 Actor 的位置、旋转和缩放,从而计算出世界空间下的位置和旋转。
local ret_1, ret_2 = NanosMath.LocalToWorld(local_location, local_rotation, actor)

Parameters

TypeParameterDefaultDescription
Vectorlocal_location Required parameter 要转换的本地位置
Rotatorlocal_rotation Required parameter 要转换的本地旋转
Base Actoractor Required parameter 定义该本地空间的 Actor

Returns

TypeDescription
Vector世界坐标下的位置
Rotator世界坐标下的旋转

RandomFloat

返回一个随机浮点值
local ret = NanosMath.RandomFloat(min, max)

Parameters

TypeParameterDefaultDescription
floatmin Required parameter 最小值
floatmax Required parameter 最大值

Returns

TypeDescription
float随机值

FInterpTo

将数字从当前值插值到目标值
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

将旋转体从当前值插值到目标值
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

以恒定步长将旋转体从当前值插值到目标值
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

将向量从当前值插值到目标值
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

以恒定步长将向量从当前值插值到目标值
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