Skip to content

BaseMotorUnit ​

运动器基类,为各类周期性或往返运动的子类(如角速度运动器)提供统一的配置入口与控制接口。通过循环、返程、单程时间、暂停时长等属性可以编排运动节奏,并借助开始、暂停、继续、返程、停止等函数对运动过程进行实时干预。运动器还会在启动与停止时触发事...

概览 ​

运动器基类,为各类周期性或往返运动的子类(如角速度运动器)提供统一的配置入口与控制接口。通过循环、返程、单程时间、暂停时长等属性可以编排运动节奏,并借助开始、暂停、继续、返程、停止等函数对运动过程进行实时干预。运动器还会在启动与停止时触发事件,便于外部逻辑感知状态变化。

继承自 Unit;不可实例化,由接口返回

函数 ​

Start ​

签名:Start()

启动运动器的运动。

启动已配置的具体运动器

lua
-- @runtime client
-- 地图中需有名为 ConfiguredLinearMotor 的已配置直线运动器
local motor = game:GetService('World'):FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then return end
motor:Start()

Pause ​

签名:Pause()

暂停运动器的当前运动。

暂停正在运行的运动器

lua
-- @runtime client
-- 目标是地图中已启动的直线运动器
local motor = game:GetService('World'):FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then return end
motor:Pause()

Resume ​

签名:Resume()

恢复已暂停的运动器运动。

恢复已暂停的运动器

lua
-- @runtime client
-- 目标是地图中已暂停的直线运动器
local motor = game:GetService('World'):FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then return end
motor:Resume()

Backtrack ​

签名:Backtrack()

使运动器立即开始返程运动。

让运动器开始返程

lua
-- @runtime client
local motor = game:GetService('World'):FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then return end
motor:Backtrack()

Stop ​

签名:Stop()

停止运动器的运动。

停止运动器

lua
-- @runtime client
local motor = game:GetService('World'):FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then return end
motor:Stop()

属性 ​

名称类型默认值说明
InitDelayTimeFloat0.0设定运动单元从启动到真正开始运动之前的等待时间,单位为秒。延迟期间运动单元保持静止。
IsCycleBoolfalse控制运动单元是否循环执行运动。开启后,运动流程会反复进行,直到停止或停用。
IsActiveBooltrue控制运动单元是否处于启用状态。关闭后运动单元不再执行运动逻辑,保持当前状态。
BackTrackingBoolfalse控制运动单元在到达目标位置后是否沿原路径返回起点。开启后运动单元将执行往返运动。
HalfCycleTimeFloat2.0设定运动单元完成单程运动所需的时间,单位为秒。单程运动指从起点到目标位置或从目标位置返回起点的单向过程。
ArrivalPauseTimeFloat0.0设定运动单元到达目标位置后的暂停时长,单位为秒。到达暂停结束后,运动单元才会继续后续动作(例如返程或结束)。
BackPauseTimeFloat0.0设定运动单元从目标位置返程回到起点后的暂停时长,单位为秒。仅当开启返程功能时生效。
DurationFloat0.0运动持续时间,类型为 Float,默认值为 0。
ActiveEventNameString""BaseMotorUnit 的运动开始事件名称属性,用于记录或指定电机单元开始运动阶段所对应的事件名。该属性为字符串类型,可直接读写。
StopEventNameString""BaseMotorUnit 的运动结束事件名称属性,用于记录或指定电机单元结束运动阶段所对应的事件名。该属性为字符串类型,可直接读写。

事件 ​

OnMotorStart ​

签名:OnMotorStart()

OnMotorStop ​

签名:OnMotorStop()