主题
AngularMotorUnit
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- BaseMotorUnit(10 属性 / 5 函数 / 2 事件)
- [AngularMotorUnit](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 指定旋转的方向与快慢,并沿用运动器基类提供的循环与时序配置能力,如 IsCycle、HalfCycleTime、ArrivalPauseTime、BackPauseTime、Duration 等。运行过程中可通过 IsActive 判断是否处于运动状态,借助 OnMotorStart 与 OnMotorStop 事件感知启动和停止。
适用场景
适合制作需要持续绕轴转动的场景元素,例如旋转平台、旋转门、环绕旋转的机关或装饰物,让挂载对象按固定角速度自动旋转而无需每帧手动改朝向。
使用要点
通过 game:CreateUnit("AngularMotorUnit", config) 或 World:CreateUnit("AngularMotorUnit", config) 创建实例,并在配置中给出 AngularVelocity 以决定旋转速度与轴向。之后按需设置 IsCycle、Duration、HalfCycleTime、InitDelayTime、ArrivalPauseTime、BackPauseTime 等参数来编排循环与停顿,再调用 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('AngularMotorUnit', {
Parent = target,
AngularVelocity = Vector3.New(0, 90, 0),
})
motor:Start()属性 (1)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
AngularVelocity | Vector3 | [0, 0, 0] | AngularMotorUnit(角速度马达单元)的角速度属性,取值类型为 Vector3,用三个分量表示角速度。该属性在 Meta 契约中标记为公开、可编辑且非只读,因此创建实例后可以在运行时读取或重新赋值。 |
