text
stringlengths 0
1.11k
|
|---|
To create a colocated experience, the virtual space must correspond with the real world position and orientation of all users in the same way. The Colocation package handles coordination with the spatial anchors and helps determine the users’ relative transformation against them. Once the Colocation package is integrated, you just hook into the users’ camera rig, the root VR GameObjects, and the networking layer. Discover then handles the colocation by placing players in the same space.
|
Assuming your app already handles networking logic, the Colocation package can help you transform your traditional multiplayer experience into a shared mixed reality experience. Discover is built this way, but your app can target any architecture you prefer, by reusing Discover’s packages and parts of its logic.
|
Colocation package uses the Shared Spatial Anchors API. If your goal is to share spatial anchors to orient users in the same space for a Mixed Reality experience, you can use this Unity Shared Spatial Anchors API directly. However, if your goal is to focus on colocation, the Colocation package can be a valuable tool for you.
|
Spatial anchors and the Colocation package overview
|
The Colocation package uses shared spatial anchors to bring multiple users together in a shared digital space, so they can experience things at the same time, in the same way, and at the same physical space. It isn’t intended to continue this behavior between sessions or in a persistent manner, unlike a normal (non-shared) spatial anchor. The difference is that shared spatial anchors are mainly used for colocation like in Discover, while normal spatial anchors are used for persisting objects in a real-life scene.
|
With Discover, this logic starts with the “host” player, who starts the gameplay session. You can also think of this player as a “master client” or a “server” player who hosts the session for all other players and has rights over the gameplay session. The host player sets up the scene and the colocated “client” players join it.
|
In this sense, the Colocation package handles shared spatial anchors so that their mechanics are behind the scenes for client players and only the host players are aware of them.
|
You can think of shared spatial anchors as the North star. It’s the only point that all players’ headsets understand in common with reference to the physical world. When the first player creates a shared spatial anchor, it says to the other players something equivalent to: “we will all use a star to help us coordinate”. Using this analogy, this shared spatial anchor, and many other spatial anchors, are visible to all players, similar to how the sky is full with stars.
|
So, the knowledge that this shared spatial anchor exists is handled by the Shared Spatial Anchors API. The API also guarantees that a shared spatial anchor has a unique ID for all users. If they get that ID, they will all mean the same shared spatial anchor.
|
All spatial anchors are given a UUID (universally unique identifier), which means no two different spatial anchors will have the same ID. If I give you the ID of my spatial anchor, it will only ever identify my spatial anchor. However, just because you have my anchor’s UUID, it doesn’t mean you can directly access my spatial anchor. Due to the private nature of your headset’s environment map, you can only access my spatial anchors if I explicitly share them with you. This happens through the Shared Spatial Anchors API. While the API only exposes anchor points, what it’s actually doing is uploading the entire environment map from my headset to the cloud, and allowing others to download the whole map. Once you have my map, I can give you the ID of the spatial anchor, and you can use that ID to find the same position in the same environment.
|
The first player must somehow transmit which of all the shared spatial anchors is the one that all peers must use, and that shared spatial anchor should be unique. In the star analogy, this means that the actual star must be commonly identifiable by all players. The transmission of the shared spatial anchor’s ID happens through a networking solution. Discover uses Photon Fusion. When a headset receives that ID, the shared spatial anchor in their room will be identified.
|
Assuming all players know which spatial anchor they must refer to, there is an extra step in the flow. All digital object transforms or the player’s transforms must be relative to that shared spatial anchor. Again in the star analogy, if the first player sees a ship in front of them, in order to transmit that ship’s position and rotation, they must transmit the relative position and orientation of the ship to the north star (that is the relative transform to the shared spatial anchor). Similar to that, to broadcast their position to others they must do that in reference to the north star.
|
Therefore, this comprises a second, critical piece of data that must be transmitted continuously in a collocated experience through a networking solution. The relative transforms of all players’ Camera rigs or the relative transform of the digital objects to the shared spatial anchors. Then, by inverting the transform, each player’s headset will be able to place these objects at the common physical space.
|
The Colocation package handles the above flow and simplifies its complexity for developers.
|
Discover’s DroneRage
|
the drone rage app image featuring three drones with weapons primed and the app title drone rage beneath them
|
DroneRage is a subapp within the Discover showcase. This game modifies the host player’s scene and transforms their room into a high-octane battlefield and throws them into an electrifying fight against relentless drones for survival.
|
You can test the game out on Applab - Discover.
|
Gif of DroneRage being played where the player is shooting at drones in a Mixed Reality setting
|
DroneRage is a colocated experience built on top of Discover. It can support up to four collocated players shooting at the drones in the same physical room.
|
The DroneRage app doesn’t call the colocation APIs explicitly. Instead once users are colocated, everything is networked everything in world space, like you normally would in any other game. For example when the enemy drones around flying around, they aren’t cognizant about any spatial anchors in use. They are simply networking in a world space like a standard multiplayer game. The shared spatial anchor is also used to orient the client players and everything is using a common world space.
|
User flow for starting the colocated experience
|
Discover uses a room code system where the host user creates a room, and gives it an explicit code (or is assigned a random 6-digit code). To join a room, a client player selects Join from the Menu and enters that code. It works this way both for remote players and colocated players.
|
The way that the menu works is about deciding whether to “join” or “join remote”. If the player joins and the app can’t find a shared spatial anchor, it joins them remotely.Set up Colocation Package
|
Unity
|
All-In-One VR
|
Quest
|
The platform for which this article is written (Unity) does not match your preferred platform (Nativa).
|
Haz clic aquí para ver la página del índice de la documentación para tu plataforma de preferencia.
|
When the scene sets up, players are synchronized. Everything else is normal Unity networking.
|
The most important part of a colocated experience is ensuring the client player is in the right place relative to the scene transmitted by the host player.
|
To do this, the host player accesses the Scene API and spawns all the objects in the scene. When the client player then joins that session, they can start interacting with these objects. The rest of this logic is a matter of placing the client players in the correct spot relative to the host player, and that’s where the shared spatial anchors come from. Once these are set up, everything else falls into place and it all converts to a network scene.
|
From the client player’s perspective, the host player sends them two things:
|
An object (such as a Unity transform) that represents it relative to the spatial anchor. In Discover, this is sent through Photon Fusion.
|
An Anchor ID that the host player is using through the Shared Spatial Anchors API to get its transform relative to the headset.
|
The Colocation package then uses these to reorient every player’s rig to the transform that the host has sent to the client players. This means that the server sends a transform and the ID, first. And then, by using that ID, there is another transform that represents where the player actually is in the first player’s space. Under the hood, the Spatial Anchors API returns the transform relative to the headset.
|
In this way, there is an absolute coordinate system which is the common world space used by the host and client players. Because of this, when you replicate the digital objects in an app by using the Colocation package, you don’t need to align the objects to the player as well. You are simply moving the root of the player’s camera rig.
|
Outline of how the Colocation package is set up
|
This process is demonstrated by the ColocationDriverNetObj class in /Assets/Discover/Scripts/Colocation/ColocationDriverNetObj.cs. Here is how the flow works in this class.
|
Set up objects In the UniTask SetupForColocation() function, the class sets up all the objects in the scene, as seen in the following code snippet:
|
m_colocationLauncher.Init(
|
m_oculusUser?.ID ?? default,
|
m_headsetGuid,
|
NetworkAdapter.NetworkData,
|
NetworkAdapter.NetworkMessenger,
|
sharedAnchorManager,
|
m_alignmentAnchorManager,
|
overrideEventCode
|
);
|
Initialize colocation launcher After the objects are set up, it initializes the colocation launcher:
|
m_colocationLauncher.RegisterOnAfterColocationReady(OnAfterColocationReady);
|
if (HasStateAuthority)
|
{
|
m_colocationLauncher.CreateColocatedSpace();
|
}
|
else
|
{
|
// Don't try to colocate if we join remotely
|
if (SkipColocation)
|
{
|
OnColocationCompletedCallback?.Invoke(false);
|
}
|
else
|
{
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.