I'm experimenting with the vertical plane, and I'm trying to place a node on a wall with the correct rotation based on that vertical plane.
here's the ARHitTestResult of the vertical plane that gets tapped:
let hitLocation = sceneView.hitTest(touchPoint, types: .existingPlaneUsingExtent)
I've tried the following:
let hitRotation = hitLocation.first?.worldTransform.columns.2
and
let anchor = hitLocation.first?.anchor
let hitRotation = anchor?.transform.columns.2
neither one of them seem to work.
And this is what I'm hoping to do:
boardNode.eulerAngles = SCNVector3((hitRotation?.x)!, (hitRotation?.y)!, 0)
I'd much appreciate it if someone could help me out with this as I can't find a lot of tutorials on ARKit yet.
EDIT
so here's what worked (thanks to Josh):
let hit = sceneView.hitTest(touchPoint, types: .existingPlaneUsingExtent)
let planeAnchor = hit.first?.anchor as? ARPlaneAnchor
guard let anchoredNode = sceneView.node(for: planeAnchor!) else { return }
let anchorNodeOrientation = anchoredNode.worldOrientation
boardNode.eulerAngles.y = .pi * anchorNodeOrientation.y
Note: .worldOrientation is way more accurate than .rotation in this case, just wanted to mention this.