我正在沿着带有 ARKit 的 SpriteKit 示例跟随并希望改变行为,而不是将精灵放在摄像机前面 - 我希望精灵始终位于地板上方的固定距离(平面?),e.g 。 eye-level。我也想使用 WorldAlignment gravityAndHeading,以便我可以随时将它放在房间的同一部分。

这是示例代码

if let currentFrame = sceneView.session.currentFrame {

    // Create a transform with a translation of 1.5 meters in front of the camera
    var translation = matrix_identity_float4x4
    translation.columns.3.z = -1.5
    let transform = simd_mul(currentFrame.camera.transform, translation)

    // Add a new anchor to the session
    let anchor = ARAnchor(transform: transform)
    sceneView.session.add(anchor: anchor)
}

当我将翻译传递给currentFrame.camera.transform时,是否需要获取相机的高度位置,或者是否有某些东西可以给出绝对或相对位置 0?

另外,我假设我应该打开平面检测并在检测到的平面上添加我的锚点? configuration.planeDetection = .horizontal