主题
LinearMotorUnit
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
- [LinearMotorUnit](2 属性)
- BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
继承成员
2 个来源 / 14 属性 / 30 函数 / 8 事件
- 来自 BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
LinearMotorUnit 是沿直线轨迹驱动单位运动的运动器单位,用 LinearVelocity 描述线速度、MotorType 描述运动器类型,并继承 BaseMotorUnit 的整套运动控制接口。它还可以通过 Duration、IsCycle、BackTracking、HalfCycleTime、ArrivalPauseTime 等属性刻画一次直线行程的节奏,并借助 OnMotorStart、OnMotorStop 事件反馈运动的开始与结束。
适用场景
适用于需要让单位沿固定直线方向单向或往复移动的场景,典型做法是创建实例后交给统一的运动控制流程驱动,并在运动开始与结束时衔接后续表现。
使用要点
从场景中获取编辑器已配置运动方向与速度的 LinearMotorUnit,再通过 Duration、IsCycle 等公开属性调整时序,并调用 Start/Pause/Resume/Stop 控制运动。
注意事项
需要设置直线方向与速度时先在编辑器中完成配置。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 | 类型 | 默认值 | 说明 |
|---|---|---|---|
LinearVelocity | Vector3 | [0, 0, 0] | LinearMotorUnit 的线性速度属性,类型为 Vector3,默认值为 (0, 0, 0)。该属性可读可写,用于记录并设置该线性马达单元的速度向量。 |
MotorType | Int | 0 (FixLinear) | 线性运动器的运动类型,决定运动器沿直线运动时的行为模式。 |
