Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARCore+Unity3D: How to make a scene oriented to north?

I've been playing around with ARCore in Unity.

What I want to achieve is spawning objects according to input GPS coordinates and current GPS position (e.g. the object should be spawned at x.xxxxx, y.yyyyy coordinates which translate to world coordinates in Unity).

I figured out that in order to place objects correctly I need to somehow maintain the north orientation.

How can it be possible with ARCore? In ARKit the scene is created so that one of the axis is heading north (according to compass reading at the scene creation moment). This is not the case with ARCore.

Is there a workaround for ARCore?

like image 410
Saico Avatar asked Oct 06 '17 09:10

Saico


1 Answers

Found the answer in Unity Docs:

https://docs.unity3d.com/ScriptReference/Compass-magneticHeading.html

function Update () {
       // Orient an object to point to magnetic north.
       transform.rotation = Quaternion.Euler(0, -Input.compass.magneticHeading, 0);
    }
like image 190
Andy Cochrane Avatar answered Sep 29 '22 14:09

Andy Cochrane