Skip to content

LinearMotorUnit

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)
    • BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
      • [LinearMotorUnit](2 属性)

继承成员

2 个来源 / 14 属性 / 30 函数 / 8 事件

直线运动器(LinearMotorUnit)是场景中的直线运动驱动单位,运动器类型(MotorType)决定其运动实现方式,而直线运动的方向与速度需预先在编辑器中配置。它运行期间可借助基类提供的运动控制能力被启动、暂停或复位,适合作为驱动场景部件沿直线滑动的动力来源。

适用场景

在关卡中搭建需要由脚本控制开合的直线滑动结构时使用该单位,例如可往复移动的场景部件或导轨类装置,先在编辑器中定义好直线方向与速度,再交给运行逻辑按需驱动。

使用要点

从场景中获取编辑器已配置运动方向与速度的 LinearMotorUnit,再通过 Duration、IsCycle 等公开属性调整时序,并调用 Start/Pause/Resume/Stop 控制运动。

注意事项

LinearVelocity 在当前 Meta 中标记为 publish=false,作者示例不得读取或写入;需要设置直线方向与速度时先在编辑器中配置。Lua 只使用 MotorType、Duration 等当前公开成员和继承自 BaseMotorUnit 的控制接口。

代码示例

启动编辑器预配置的直线运动器

lua
-- @runtime client
local World = game:GetService('World')
local motor = World:FindFirstChild('ConfiguredLinearMotor', true)
if motor == nil or not motor:IsA('LinearMotorUnit') then
    print('请先在编辑器中配置 LinearMotorUnit')
    return
end
motor.Duration = 5
motor:Start()

属性 (2)

Name类型默认值说明
LinearVelocityVector3[0, 0, 0]用于表示直线运动电机目标线速度的属性,该属性的取值为三维向量,决定直线运动电机在空间中的运动速度。
MotorTypeInt0 (FixLinear)线性运动器的运动类型,决定运动器沿直线运动时的行为模式。

关联类型