atmoky Engage Server SDK is now available! Check out the documentation to learn more.
Documentation
Real-time Communication
Position Synchronisation

Position Synchronisation

For a consistent experience across all participants, the position 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 of the local participant changes, the new position is broadcasted to all other participants. Additionally, the position will be also broadcasted regularly at a lower frequency, even if the position hasn't changed. This is to make sure that the position is still broadcasted, even if the local participant is not moving, so that other participants joining the space later will receive the position of the local participant.
Setting the position of the local participant will trigger a broadcast:
localParticipant.setPosition(1, 2, 3);
Future updates will also include the rotation of the local participant.

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 },
});

atmoky Logo

© 2023 atmoky, GmbH.
All rights reserved.

We use cookies to measure and improve your browsing experience, and serve personalized ads or content.