Hi everyone,
I’m working on a Unity AR project for iOS and I’ve run into a tricky problem. I’m hoping someone here might have some insights.
The issue: When I start my AR app, the placement of AR objects in the real world is inconsistent depending on which direction I’m facing (north, east, south, or west). Basically, if I start the app while facing north, the objects appear in one set of positions. But if I restart the app while facing east, the same objects appear in different positions relative to the real world.
What I want: I need the AR objects to appear in consistent real-world locations regardless of which direction the device is facing when the app starts.
Technical details:
- Using Unity for iOS
- Implementing AR functionality
Has anyone encountered a similar issue or know of a good way to ensure consistent real-world alignment regardless of initial device orientation? Any tips on using compass data, ARKit features, or other methods to solve this would be greatly appreciated!
Thanks in advance for any help!
1 Like
So I use MakeContentAppearAt() to place the Game World (parent object) under the Player on a confirmed plane in my AR Assets. Using the data from the sensor mentioned above, I believe I could rotate the Game World as needed.
Solution to Inconsistent Device Orientation After AR Session Reset
I managed to resolve the issue of inconsistent device orientation after resetting the AR session by aligning my AR scene with the device’s compass heading. The key was to ensure that the AR content always aligns with a consistent real-world direction, regardless of the device’s orientation when the session resets.
Here’s the method I used:
public float AlignWithWorldNorth()
{
// Get the device's current compass heading relative to true north
float compassHeading = Input.compass.trueHeading;
// Calculate the rotation needed to align the AR scene with the desired north
float trueRotation = (compassHeading - _settings.RoomNorthOffset + 360) % 360;
return trueRotation;
}
Explanation:
_settings.RoomNorthOffset: A configurable setting that represents the offset between the real-world north and the desired “north” in the AR scene. This allows for calibration if the AR scene’s north doesn’t perfectly align with true north.
- Calculation: By subtracting the
RoomNorthOffset from the compass heading, we determine the rotation needed to align the AR content with the desired orientation. Adding 360 and using the modulo operator ensures the result is within the range of 0 to 360 degrees.
1 Like
Hello @samuel_unity196,
I am working on trying to align my game objects to the correct orientation in Unity and stumbled up this post. I specifically wanted to ask what is “_settings.RoomNorthOffset”? Is this something provided by unity or something you created? If it is provided by unity, where can I find documentation on it? Thanks,
Mason Gaw
A second question I had is how are you calling this function? Is this something you are calling on Update(), or on a InvokeRepeating(), or just once at the beginning of the session?
Thanks,
Mason Gaw
1 Like