主题
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 指定摆动角速度,并复用基类的循环与返程时序参数来调节摆动节奏。作为运动器,它在启动后才驱动目标运动,运行过程中可以随时暂停、恢复、回退或停止。
适用场景
适合制作钟摆、摆锤机关、来回摆动的吊桥或往返平台等需要周期往复摆动的对象。把运动器挂到目标单位下并启动后,目标便会持续按设定节奏摆动。
使用要点
先通过 game:CreateUnit("PendulumMotorUnit", config) 或 World:CreateUnit("PendulumMotorUnit", config) 创建实例并挂载到目标单位下,设置 AngularVelocity,再按需配置 IsCycle、BackTracking、HalfCycleTime、ArrivalPauseTime、BackPauseTime、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] | 角速度属性,类型为 Vector3,默认值为 (0, 0, 0),可读可写。它用于配置 PendulumMotorUnit(摆锤电机单元)的角速度参数,是创建实例时可通过配置表传入的属性之一。 |
