Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

[Bug] GravityAndHeading incorrect in EnableGeoAnchors example #829

Closed sam598 closed 3 years ago

sam598 commented 3 years ago

I am writing this with the full understanding that this feature is not officially integrated. I wanted to call this out for whenever it is.

When using the following script in the SimpleAR scene, ARKit aligns the camera so that the scene's Z+ axis is aligned with the device's understanding of North.

using UnityEngine;
using UnityEngine.XR.ARFoundation;

#if UNITY_IOS
using UnityEngine.XR.ARKit;
#endif

public class HeadingScript : MonoBehaviour
{
    void Start() => Input.location.Start();

    void Update()
    {
        if (Input.location.status != LocationServiceStatus.Running)
            return;

        if (GetComponent<ARSession>().subsystem is ARKitSessionSubsystem subsystem)
        {
            subsystem.requestedWorldAlignment = ARWorldAlignment.GravityAndHeading;
        }
    }
}

The EnableGeoAnchors example uses subsystem.requestedWorldAlignment = ARWorldAlignment.GravityAndHeading; as well. However the resulting behavior is very different.

Instead a moment after the scene starts, the camer's world Z+ axis will be 90 degrees to the right of wherever the camera is facing when the scene starts. This arbitrary positioning consistently happens in every direction.

This can be tested by placing an object at position (0,0,3) and observing it's position change.

The good news is that the GeoAnchors behave as expected. Their position and rotation relative to the camera is consistent, and the anchor's local Z+ axis always faces North.

I am not sure if this is expected behavior from ARKit, or something internal with how ARFoundation interprets the camera pose. But ideally the camera's world Z+ axis would be consistently facing North.

Tested with an iPhone 12 Pro Max, iOS 15 beta 1.

tdmowrer commented 3 years ago

Please log a bug by following these instructions: https://unity3d.com/unity/qa/bug-reporting

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sam598 commented 3 years ago

It's not a bug with Unity, it's an unexpected behavior in AR Foundation, either caused by ARKit or AR Foundation's interpretation of ARKit.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.