Skip to content

RodConstraint

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)
    • [RodConstraint](10 属性)

继承成员

1 个来源 / 4 属性 / 25 函数 / 6 事件

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类型默认值说明
EnabledBooltrue控制约束是否启用。
Attachment0Attachment-杆状约束(RodConstraint)的第一个连接附件,对应约束一端的附着对象。
Attachment1Attachment-杆状约束(RodConstraint)的第二个连接附件,对应约束另一端的附着对象。
LengthFloat5.0杆的长度,以空间单位表示。
LimitsEnabledBoolfalse是否启用端部角度限制。
LimitAngle0Float0.0Attachment0 端的角度限制,单位为度。
LimitAngle1Float0.0Attachment1 端的角度限制,单位为度。
ThicknessFloat0.1约束可视化显示的粗细。
ActiveBoolfalse指示 RodConstraint 是否处于激活状态。
CurrentDistanceFloat0.0当前两个 Attachment 之间的实际距离,以空间单位表示。

关联类型