Search Unity

Camera movement in ARKit

Discussion in 'AR' started by mgaldos87, Sep 19, 2017.

  1. mgaldos87

    mgaldos87

    Joined:
    Dec 8, 2016
    Posts:
    1
    Hi everyone,

    I'm kind of new to the world of AR/VR and have been having trouble getting the camera to act the way I intend it to. Basically, what I want to do is make the AR Camera teleport once it hits a collider.

    The way it is set up is, I have a parent object containing a character controller, a rigidbody and a first person controller script. then I have a child object which is the camera, and that one only has the camera with the UnityARVideo and UnityARCameraNearFar scripts.

    Now, I can make the teleportation happen in a non-AR environment in Unity by simply attaching a script with a trigger event that will move the camera and the parent object it's under onto a different position on the world. However, when I try to translate this into a scene where I use ARKit, I cannot get the same behavior. My camera simply goes through the collider. Normally I would debug using the console, but since I am on the phone, I have no way of telling what is going on (which bring me to another question --is there a way to debug like this)?

    Just to be safe, I tried a different configuration, getting rid of the parent object and attached all components to the AR Camera + a sphere collider to trigger the teleportation. I had no luck either.

    I have a couple of suspicions as to why this doesn't work. The first one is that since AR tracks position in both the real and virtual world, if I try to teleport, this might mess with the program since I have physical world coordinates... or something like that, right? Or maybe it is simply that I am missing some sort of component on the camera so that it triggers the event.

    My second suspicion (and the one I think is probable the most accurate) is that the camera is moving around the space of the parent object. So, if I move around with the phone, the camera moves but the parent object stays in place. Therefore there is nothing to trigger the teleportation.

    Could any of the above be right? Does anyone have any suggestions on how to get around this problem? Thanks a lot everyone!
     
  2. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    If I understand the question....
    If you're using ARkit, the definition of it is that it's an always-looking camera that's always where the device is. So you can't teleport because you can only use the AR Data while you let the kit control that cam.

    The option that would work is to teleport objects in the scene relative to you, so kind of the inverse. All the 3d objects can pretty much be treated as if they're in a regular 3d world to an extent.
     
    jimmya likes this.
  3. dagon

    dagon

    Joined:
    Jan 4, 2013
    Posts:
    20
    Because arkit always update camera position after end frame.
    So if you want teleport you can move parent of camera and reset track by function :
    UnityEngine.XR.iOS.UnityARSessionNativeInterface.RunWithConfigAndOptions(ARKitWorldTrackingSessionConfiguration config, UnityARSessionRunOption runOptions);
    with parameter UnityARSessionRunOption.ARSessionRunOptionResetTracking
     
  4. jimmya

    jimmya

    Joined:
    Nov 15, 2016
    Posts:
    793
    I wouldn't put any transform on the camera parent, because ARKit expects the camera to be in a certain world position, and planes and features points created will end up in the wrong spot if you have a parent transform. The method proposed above would work (move the content relative to the camera).
     
  5. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    We could spawn the tracking data in the same parent as the camera, and then it would still work.