0

I've placed a node in Scenekit/ARKit

Now I want to move node/object to right and left with help of buttons. Issue is when I moves my camera/device and press right button, node moves in direction of axis it was first initiated, Not moves right with respect to camera. How can I achieve this?

current code on tapping right button

position.x += 0.2
Haris
  • 1,822
  • 2
  • 22
  • 44
  • This is because the Coordinate System of ARKit is placed initial, and then remains static until you reset the ARSession. You will have to find a solution to determine the angle between the initial position and the current camera positioin. This can be quite tricky. – ZAY Mar 12 '22 at 07:33
  • Can you please share a [minimum reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) ? – de. Mar 15 '22 at 12:00
  • @de. Can you kindly explain what kind of example you require from my side to reproduce? bcz this will happen with every project/node when you change the position of camera. – Haris Mar 16 '22 at 05:13
  • I usually create a new Xcode project and drop minimal code in to show the issue, ideally only in one file, and paste the code in the question. Example: https://stackoverflow.com/a/66475284/921573 – de. Mar 16 '22 at 09:37

1 Answers1

2

Here is the solution

guard let front = sceneView.pointOfView?.simdWorldFront else {return}
let horazontalRight = cross(front, simd_float3(0,1,0))
    
// for moving right
node.position +=  SCNVector3(horazontalRight *  0.01)
Haris
  • 1,822
  • 2
  • 22
  • 44