主题
RigidConstraint
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [RigidConstraint](4 属性)
继承成员
1 个来源 / 4 属性 / 25 函数 / 6 事件
- 来自 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
- 属性:
RigidConstraint 描述两个 Attachment 实例之间的刚性连接;当前公开契约可通过 Attachment0/Attachment1 直接引用端点。
适用场景
仅建议检查编辑器中已经绑定完成、并在目标运行包验证过的刚性约束;稳定跟随优先采用成熟的焊接或父子层级方案。
使用要点
从场景中查找预配置的 RigidConstraint 并读取状态;若动态创建,Attachment0/Attachment1 应传入已有 Attachment 实例。
注意事项
Attachment0 和 Attachment1 使用 Attachment 实例引用,不需要读取 UnitId。当前运行包仍实测出现动态创建后表现为弹性连接、对象固定异常等问题;修复前请优先使用编辑器预配置的 RigidConstraint,需要稳定刚性跟随时采用已验证的 WeldConstraint 或父子层级方案。
代码示例
读取编辑器预配置的刚性约束
lua
-- @runtime server
local World = game:GetService("World")
local constraint = World:FindFirstChild("MyRigidConstraint", true)
if constraint == nil or not constraint:IsA("RigidConstraint") then
print("请先在编辑器中配置 RigidConstraint")
return
end
print("已找到刚性约束:", constraint.Name)属性 (4)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Enabled | Bool | true | 控制 RigidConstraint 是否启用。 |
Attachment0 | Attachment | - | RigidConstraint 约束关联的第一个 Attachment 附件。约束通过两个 Attachment 确定被连接对象上的作用点,Attachment0 即为这一对附件中的第一个端点。 |
Attachment1 | Attachment | - | RigidConstraint 约束关联的第二个 Attachment 附件。与 Attachment0 成对使用,用于确定刚性连接的另一侧锚点。 |
Active | Bool | false | 指示 RigidConstraint 当前是否处于激活状态。 |
