主题
PendulumMotorUnit
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
- [PendulumMotorUnit](1 属性)
- 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
- 属性:
摆锤运动器是一种以摆锤方式驱动对象运动的场景运动器,通过 AngularVelocity 属性设定摆动角速度,并继承 BaseMotorUnit 的完整运动控制能力,可配合 IsCycle、BackTracking、HalfCycleTime、ArrivalPauseTime、BackPauseTime 与 Duration 等参数配置循环、返程与停留时序,同时借助 OnMotorStart、OnMotorStop 事件感知运动状态变化。
适用场景
适用于制作钟摆、闸门、吊桥等需要周期性摆动或往复运动的场景机关,通常在创建后设置角速度与循环时序,再启动运动即可驱动目标持续摆动。
使用要点
先通过 game:CreateUnit 或 World:CreateUnit 创建 PendulumMotorUnit 实例,并配置 AngularVelocity 与基类提供的 IsCycle、BackTracking、Duration 等时序属性;随后调用 Start 启动运动,运行过程中可使用 Pause、Resume、Backtrack、Stop 控制状态,并监听 OnMotorStart、OnMotorStop 事件以同步外部逻辑。
注意事项
BaseMotorUnit 是各种运动器(Angular/Linear/CurveVel/Pendulum/Waypoint)的基类,运行时不应直接创建 BaseMotorUnit;演示基类 API 时请创建具体子类。通过 IsCycle、BackTracking、HalfCycleTime、ArrivalPauseTime、BackPauseTime 与 Duration 配置循环、返程和时序,再调用 Start/Pause/Resume/Backtrack/Stop 控制运动。运动器通过 OnMotorStart / OnMotorStop 事件回调感知状态。
代码示例
创建往复摆锤运动器并驱动目标
lua
-- @runtime client
local World = game:GetService('World')
local target = World:CreateUnit('WorldUnit', { Position = Vector3.New(0, 3, 0) })
local motor = World:CreateUnit('PendulumMotorUnit', {
Parent = target,
AngularVelocity = Vector3.New(0, 30, 0),
Duration = 10,
IsCycle = true,
BackTracking = true,
HalfCycleTime = 2,
})
motor:Start()属性 (1)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
AngularVelocity | Vector3 | [0, 0, 0] | PendulumMotorUnit 的角速度属性,以三维向量表示摆动马达单元的旋转角速度。 |
