How to move SCNNode just below ARCamera?

I am making an augmented reality application where the user must throw the ball at the goal. I used the following code to position the ball 10 cm from 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) 

At the moment, the game looks like this, but I want to move the ball closer to the bottom of the screen.

enter image description here

+9
swift augmented-reality arkit
source share
2 answers

I ended up finding a solution:

Replacing the following line:

 translation.columns.3.z = -0.1 

from:

 translation.columns.3.x = -0.1 
+1
source share

As an option, you can use the following approach for X , Y, and Z at the same time:

 translation.columns.3 = simd_float4(-0.1, 0, 0, 1) 

The last element in columns.3 is a uniform coordinate , it is 1 .

enter image description here

The columns of a 4x4 matrix look like this:

 public var columns: (simd_float4, simd_float4, simd_float4, simd_float4) 

Hope this helps.

0
source share

All Articles