Placing Virtual Content

Use the following information to understand how to place and orient virtual content in a Shared AR experience.

Peer Poses

In an ARNetworking session, all peers begin in their own coordinate systems, where the origin (0,0,0) is located where their device was when the ARSession started running. Upon reaching stability, a peer’s pose will snap to be in the host’s coordinate system.

By default, all stable peers will broadcast their pose to all other peers. Pose broadcasting can be configured based on your application’s requirements.

using Niantic.ARDK.AR.Networking;

IARNetworking arNetworking;

// To enable
arNetworking.EnablePoseBroadcasting();

// To disable
arNetworking.DisablePoseBroadcasting();

// To configure how often poses are broadcast
arNetworking.SetTargetPoseLatency(latency);

The latest available pose of each peer can be retrieved through the IARNetworking interface.

var allPeerPoses = arNetworking.LatestPeerPoses;
var myPeerPose = arNetworking.ARSession.CurrentFrame.Camera.Transform;

Alternatively, peer pose updates, including those for the local device, can be subscribed to.

using Niantic.ARDK.Utilities;

IARNetworking _arNetworking;
Dictionary<IPeer, GameObject> _peerGameObjects;

void SubscribeToPeerStateUpdates()
{
  _arNetworking.PeerPoseReceived += OnPeerPoseReceived;
}

void OnPeerPoseReceived(PeerPoseReceivedArgs args)
{
  var peer = args.Peer;
  var pose = args.Pose;

  // Use this information to attach a GameObject to a player,
  // have in-game characters look at a player, have an AI
  // shoot at a player, etc.
  var peerGameObject = _peerGameObjects[peer];
  peerGameObject.transform.position = pose.ToPosition();
  peerGameObject.transform.rotation = pose.ToRotation();
}

Placing Virtual Content in a Shared World

When using an ARSession, the origin (0,0,0) will be at the original location of the device when the session was run. 1 unit (in Unity space) corresponds to roughly 1 meter in the real world.

When AR spaces are connected through an ARNetworking session, all player will initially have their own coordinate systems, corresponding to their startup locations. An object placed at position (X, Y, Z) in each player’s virtual environment will not appear in the same position for everyone in the real-world environment.

However, upon completing localization, the positions of all non-host devices will “move” to new positions corresponding to their relative locations on the host’s coordinate system. At this point, all clients are using the same coordinate system (the host’s), and placing a virtual object at position (X, Y, Z) will look the same for everyone in the real world as well.