Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AR Foundation: Re-positioning World Origin

Discussion in 'AR' started by bananaking932_unity, Jul 12, 2018.

  1. bananaking932_unity

    bananaking932_unity

    Joined:
    Jul 12, 2018
    Posts:
    1
    I was wondering if anyone knows of a way to reposition the game's world origin after an AR session starts using AR Foundation? The ideal mechanic being tapping on a detected plane and the world origin moves to that tapped position.

    Trying to achieve the same functionality as the SetWorldOrigin method that is included in ARKit: https://developer.apple.com/documentation/arkit/arsession/2942278-setworldorigin
     
  2. jimmya

    jimmya

    Joined:
    Nov 15, 2016
    Posts:
    793
    This is not functionality that is exposed in ARFoundation yet, but there is a way to do something similar by changing the transform of the AR Session Origin so that the Camera appears to be in a different part of your virtual world.
     
  3. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Have you seen https://docs.unity3d.com/Packages/c...Origin_MakeContentAppearAt_Transform_Vector3_ ? It was designed to achieve something similar to what you describe.
     
    angles20 likes this.
  4. CJRobertson932

    CJRobertson932

    Joined:
    Jul 11, 2016
    Posts:
    6
    I am the same users as the one that started this thread. I apparently logged in with Google when I made this.

    That did indeed help with what I was trying to solve! Thank you for pointing it out, I appreciate it.
     
  5. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Sorry for necropost... But is setWorldOrigin available in ARFoundation yet to be used on Android? Is that a possibility or in the works? I'm aware of MakeContentAppearAt, but I'm wondering about repositioning the Scene origin or is that the only appropriate way to go about this
     
  6. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    In the code,I was changing the model(not prefab) in the heirarchy visiblity to true when an image is tracked.But the problem is that the model is not coming in front of the ARcam instead it shows from where I started the app for tracking.Anyway to update position once the image is tracked.That is Reset Arcam position such that the model will appear exactly at the front.
    Code (CSharp):
    1.  
    2. void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    3.     {
    4.      
    5.           foreach (var trackedImage in eventArgs.added)
    6.           {
    7.            
    8.                 if (trackedImage.referenceImage.name == "Img1")
    9.                 {
    10.  
    11.                     Showprefabs.SetActive(true);
    12.                     //How to adjust the position of model to come in front of AR cam?
    13.                 }
    14.          }
    15.  
    16.  
    17.     }
    18.  
     
  7. sweazey48

    sweazey48

    Joined:
    Sep 25, 2019
    Posts:
    4
    With regards to setting rotation according to the AR Session Origin, how would one make the rotation of an object consistent with the world's direction? In my case when the app starts it sets the world's axes according to the current facing direction, meaning that Vector3.left would be relative to the device and not a relative consistent world axis. Essentially, I want to make it so each time the application is started and an object with a direction of Vector3.left is placed, it places to facing the same direction each time. I've tried setting the object and the ARSessionOrigin to have a consistent rotation, and I've tried setting it to North. Nothing seems to be working and I'm not sure what direction to take this, any advice would be appreciated.
     
  8. sbethge

    sbethge

    Joined:
    Mar 20, 2019
    Posts:
    16
    You will need to use an absolute reference, such as the device compass, to rotate your objects. World mapping otherwise has no idea about directions or what was where before. You can save world maps though. If you use the compass, rotating the camera does not make sense I think because the camera is updated through ARKit/ARCore continuously. Rotating the session origin only makes sense if all your objects are children of AR Session Origin. I found that rotating another parent with all objects once against the compass works alright but is of course dependent on the compass accuracy.
     
    swapnilNeo likes this.