主题
Attachment
Attachment 是依附在父级单元上的坐标锚点,用局部的 Position、Rotation、Orientation 与 CFrame 描述自身变换,同时提供 WorldPosition、WorldRotation、WorldCFram...
概览
Attachment 是依附在父级单元上的坐标锚点,用局部的 Position、Rotation、Orientation 与 CFrame 描述自身变换,同时提供 WorldPosition、WorldRotation、WorldCFrame 等按父级世界变换换算出的世界空间读写入口。它还带有 Axis、SecondaryAxis、Visible 等辅助描述,并可通过 GetConstraints 查询挂载在该锚点上的约束。它本身不承担层级之外的职责,主要作为约束连接与位置对齐的参照点。
继承自
Unit;可通过World:CreateUnit("Attachment", ...)创建;返回单个单位
函数
GetConstraints
签名:GetConstraints() -> Array
获取引用当前 Attachment 的约束单位,返回这些约束单位组成的数组副本。
返回值 Array — 引用当前 Attachment 的约束单位数组副本。
读取锚点引用的约束
lua
-- @runtime client
local World = game:GetService('World')
local attachment = World:FindFirstChild('MyAttachment', true)
if attachment == nil or not attachment:IsA('Attachment') then
print('请先在编辑器中准备已连接约束的 Attachment')
return
end
for _, linkedConstraint in ipairs(attachment:GetConstraints()) do
print('约束名称:', linkedConstraint.Name)
end属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Position | Vector3 | [0.0, 0.0, 0.0] | Attachment 在父级空间下的局部位置。 |
Rotation | Quaternion | [0.0, 0.0, 0.0, 1.0] | Attachment 的局部旋转,以四元数表示。 |
Orientation | Quaternion | - | Attachment 的局部朝向,以四元数表示。 |
CFrame | CFrame | - | Attachment 的局部 CFrame,用于表达该挂点在父单位本地坐标系下的位置与朝向,类型为 CFrame。 |
WorldPosition | Vector3 | - | Attachment 在世界空间下的位置。 |
WorldRotation | Quaternion | - | Attachment 的世界空间旋转,以四元数表示。 |
WorldCFrame | CFrame | - | Attachment 在世界坐标系下的 CFrame,类型为 CFrame,用于表达该挂点在场景世界空间中的位置与朝向。 |
Axis | Vector3 | - | Attachment 的主轴方向,以局部空间下的单位向量表示。 |
SecondaryAxis | Vector3 | - | Attachment 的副轴方向,以局部空间下的单位向量表示。 |
Visible | Bool | true | 控制编辑器或调试显示中该 Attachment 锚点是否可见。 |
ShowOrientation | Bool | false | Visible 为 true 时,控制是否显示该 Attachment 的朝向辅助标记。 |
