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

前端 未结 4 1484
走了就别回头了
走了就别回头了 2021-02-02 03:08

I have moving objects which I want to have be able to collide with me the player. I have the ability to launch objects from me by getting my current position/direction at that t

4条回答
  •  耶瑟儿~
    2021-02-02 03:42

    In SceneKit, everything that can have a position in the scene is (attached to) a node. That includes not just visible objects, but also light sources and cameras. When you use ARSCNView, there's still a SceneKit camera, but ARKit controls its position/orientation.

    SceneKit nodes create a hierarchy: every node's position (and orientation etc) are relative to its parent node. If the parent node moves within the scene, its children move along with it so that they keep the same parent-relative positions. So, if you want something to always keep the same position relative to the camera, you should make that content a child of the camera node.

    Even in scenes where you don't create a camera yourself — such as when SceneKit and ARKit manage the camera for you — you can get the node containing the current camera with the view's pointOfView property. (Note: ARSCNView is a subclass of SCNView, most of whose useful API is defined by the SCNSceneRenderer protocol.)

    You may have to wait until the session starts running to access the ARKit-managed camera node.

提交回复
热议问题