Search code examples
swiftaugmented-realityarkit

How to move an SCNNode to just below ARCamera?


I'm making an Augmented Reality app where the user has to throw a ball at a target. I used the following code to position the ball 10 cm in front of the screen:

var translation = matrix_identity_float4x4
translation.columns.3.z = -0.1
print(translation.debugDescription)
print(frame.camera.transform)
projectile.simdTransform = matrix_multiply(frame.camera.transform, translation)

Currently the game looks like this, but I want to move the ball to near the bottom of the screen.

enter image description here


Solution

  • I ended up finding a solution:

    Replacing the following line:

    translation.columns.3.z = -0.1
    

    with:

    translation.columns.3.x = -0.1