Position Synchronisation
For a consistent experience across all participants, the position and orientation of one participant in space should be the same for all other participants. This makes sure that all participants see and hear the same scene, but from different perspectives.
In game-like applications, this synchronisation is usually performed by the application's backend. However, some applications nowadays work server-less, so there isn't that kind of backend anymore, or they utilize pixel streaming, where sending all participants' positions down to the client isn't necessary any more for rendering the scene.
For these cases, atmoky Engage provides a position sync feature, which uses the WebRTC data channel to send the position of the local participant to all other participants. They in turn will receive the position and update the remote participant's position accordingly.
Enabling position sync
This feature can be enabled when setting up the space using
SpaceOption.positionSync
as it is disabled by default.let space = new Space({ positionSync: true });
If enabled, whenever the position or the orientation of the local participant changes, the updated data is broadcasted to all other participants. Additionally, the data will be also broadcasted regularly at a lower frequency, even if the position or orientation hasn't changed. This is to make sure that also participants joining the space later will receive the most recent data of the local participant.
Setting the position of the local participant will trigger a broadcast:
localParticipant.setPosition(1, 2, 3);
Similarly, setting the orientation of the local participant will trigger a broadcast:
localParticipant.setOrientationQuaternion(1, 0, 0, 0);
Note that setting the orientation of the local participant is only meaningful when the corresponding
RemoteParticipant
is using a directivity pattern that is orientation-dependent.Audio Listener position vs. Local Participant position
Why the position of the local participant and not the audio listener?
The audio listener's position is the position from which the remote participants are heard (similar to the camera position in 3D graphics rendering).
The local participant's position is the position from which the remote participants hear the local participant.
In some applications these two positions might be the same, but they don't have to be. For example in a third-persion view application, the audio listener's position might be the position of the camera, while the local participant's position is the position of the avatar. When switching to first-person view, the audio listener's position might be the same as the local participant's position. But even then you could argue that the audio listener's position should be the position of the ears, while the local participant's position should be the position of the mouth.
Adjusting the broadcast frequency
There are two different broadcast intervals:
- The active interval is used when the position of the local participant changes. The default value is
0.1
(seconds). - The inactive interval is used when the position of the local participant hasn't changed. The default value is
1.0
(seconds).
These values can be adjusted by passing
PositionSyncOptions
to the SpaceOption.positionSync
option:let space = new Space({
positionSync: { interval: 0.2, inactiveInterval: 2.0 },
});