主题
RodConstraint
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [RodConstraint](10 属性)
继承成员
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
- 属性:
RodConstraint 描述两个已绑定 Attachment 之间保持固定距离的杆约束。
适用场景
读取或调整编辑器中已经完成 Attachment 绑定的杆约束。
使用要点
从场景树中查找预配置的 RodConstraint,再读取长度与状态;动态创建时通过 Attachment0/Attachment1 传入已有 Attachment 实例。
注意事项
Attachment0 和 Attachment1 是公开的 Attachment 对象引用,不要传 UnitId 字符串或数字。物理约束建议在服务端创建和调整。
代码示例
读取编辑器预配置的杆约束
lua
-- @runtime server
local constraint = game:GetService('World'):FindFirstChild('MyRodConstraint', true)
if constraint == nil or not constraint:IsA('RodConstraint') then return end
print('杆约束长度:', constraint.Length)属性 (10)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Enabled | Bool | true | 控制约束是否启用。 |
Attachment0 | Attachment | - | 杆状约束(RodConstraint)的第一个连接附件,对应约束一端的附着对象。 |
Attachment1 | Attachment | - | 杆状约束(RodConstraint)的第二个连接附件,对应约束另一端的附着对象。 |
Length | Float | 5.0 | 杆的长度,以空间单位表示。 |
LimitsEnabled | Bool | false | 是否启用端部角度限制。 |
LimitAngle0 | Float | 0.0 | Attachment0 端的角度限制,单位为度。 |
LimitAngle1 | Float | 0.0 | Attachment1 端的角度限制,单位为度。 |
Thickness | Float | 0.1 | 约束可视化显示的粗细。 |
Active | Bool | false | 指示 RodConstraint 是否处于激活状态。 |
CurrentDistance | Float | 0.0 | 当前两个 Attachment 之间的实际距离,以空间单位表示。 |
