I am playing around in Realitykit and would like an Entity to always look at camera. I've seen similar questions on stackoverflow and developer forums and followed their suggestion to use look(at) method. I am aware that reality composer can achieve the same effect using behavior but I would later have to use the same technique to anchor an Arrow to the camera using AnchorEntity and have it look at another entity in the scene for user navigation.
I am using look(at) method to orient the entity to the camera right now by calling it in ARKit session Didupdate method, however, it is broken:
entity.look(at: arView.cameraTransform.translation, from: entity.position, upVector: [0,0,0], relativeTo: nil)
This will move my entity to a new position in the scene and since it is called at ARKit session Didupdate it will keep moving further and further away every frame. I thought it is not supposed to move since I've set the "from:" to object's current position so it always move to where it was and hence static. My entity is an AnchorEntity that act as a root entity for the model loaded from reality composer.
I am using look(at) method to orient the entity to the camera right now by calling it in ARKit session Didupdate method, however, it is broken:
entity.look(at: arView.cameraTransform.translation, from: entity.position, upVector: [0,0,0], relativeTo: nil)
This will move my entity to a new position in the scene and since it is called at ARKit session Didupdate it will keep moving further and further away every frame. I thought it is not supposed to move since I've set the "from:" to object's current position so it always move to where it was and hence static. My entity is an AnchorEntity that act as a root entity for the model loaded from reality composer.
after some investigation, I found the problem. You CANNOT anchor it to an anchor object, such as face, camera, plane. It messed up the position system!!! Instead, anchor it to the world origin and if you want to move it, just sets its transform every frame. this is not optimized but it is the only way this function will work!