How do you attach an object to your camera position using ARKit Swift?

I have moving objects that I want to have in order to collide with me with a player. I have the ability to run objects from me, getting my current position / direction at that time, but I do not understand how to attach an object to it, which will constantly monitor my positioning.

+4
source share
3 answers

In SceneKit, anything that can have a position in the scene is tied to a node. This includes not only visible objects, but also light sources and cameras. When you use ARSCNView, there is still a SceneKit camera, but ARKit controls its position / orientation.

SceneKit nodes create a hierarchy: each node position (and orientation, etc.) refers to its parent node. If the parent node moves inside the scene, its children move with it so that they keep the same parent positions. So, if you want something to always be kept in the same position relative to the camera, you must make this content a child of the node camera.

, , , SceneKit ARKit, node, , pointOfView. (: ARSCNView SCNView, API SCNSceneRenderer.)

, , ARKit node.

+15

ARSCNView pointOfView. node.

let ball = SCNSphere(radius: 0.02)
ballNode = SCNNode(geometry: ball)
ballNode?.position = SCNVector3Make(0, 0, -0.2)
sceneView.pointOfView?.addChildNode(ballNode!)

node .

+6

, ( x, y, z) .

    let pov = sceneView.pointOfView
    let position = pov?.position

    let x = position?.x
    let y = position?.y
    let z = position?.z
0

Source: https://habr.com/ru/post/1679189/


All Articles