主题
HingeConstraint
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [HingeConstraint](16 属性)
继承成员
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
- 属性:
HingeConstraint 描述两个已绑定 Attachment 之间绕共享轴旋转的铰链约束。
适用场景
读取或调整编辑器中已经完成 Attachment 绑定的门轴、旋转平台等铰链结构。
使用要点
从场景中查找预配置的 HingeConstraint,再调整 LimitsEnabled、ActuatorType、TargetAngle 等公开属性。
注意事项
Attachment0 和 Attachment1 使用已存在的 Attachment 实例引用,不要传 UnitId 字符串或数字。物理约束建议在服务端创建和调整;也可继续使用编辑器预配置的绑定。
代码示例
调整编辑器预配置的铰链约束
lua
-- @runtime server
local hinge = game:GetService('World'):FindFirstChild('MyHingeConstraint', true)
if hinge == nil or not hinge:IsA('HingeConstraint') then return end
hinge.Enabled = true
hinge.LimitsEnabled = true
hinge.LowerAngle = -45
hinge.UpperAngle = 90
print('铰链角度范围:', hinge.LowerAngle, hinge.UpperAngle)属性 (16)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Enabled | Bool | true | 是否启用铰链约束。 |
Attachment0 | Attachment | - | 铰链约束的第一个连接附件,用于指定约束在世界中的一端锚点。通过该属性可获取或设置作为约束连接点之一的 Attachment 实例。 |
Attachment1 | Attachment | - | 铰链约束的第二个连接附件,用于指定约束在世界中的另一端点。通过该属性可获取或设置作为约束连接点之一的 Attachment 实例。 |
ActuatorType | Int | Enums.ActuatorType.None | 铰链约束的驱动类型,决定约束如何施加力或运动。 |
AngularVelocity | Float | 0.0 | Motor 模式下的目标角速度,单位 rad/s。 |
MotorMaxTorque | Float | 0.0 | Motor 模式下的最大扭矩。 |
MotorMaxAcceleration | Float | 500000.0 | Motor 模式下的最大角加速度,单位 rad/s²。 |
TargetAngle | Float | 0.0 | Servo 模式下的目标角度,单位度。 |
AngularSpeed | Float | 0.0 | Servo 模式下的角速度,单位 rad/s。 |
ServoMaxTorque | Float | 0.0 | Servo 模式下的最大扭矩。 |
AngularResponsiveness | Float | 0.0 | Servo 模式下的响应灵敏度,控制到达目标角度的速度。 |
LimitsEnabled | Bool | false | 是否启用角度限制。 |
LowerAngle | Float | -45.0 | 角度限制的最小角度,单位度。 |
UpperAngle | Float | 45.0 | 角度限制的最大角度,单位度。 |
Restitution | Float | 0.0 | 约束在达到角度限制时的弹性,取值范围 0 到 1。 |
Radius | Float | 0.5 | 约束在编辑器中的可视化半径。 |
