Step 6 — Entering the scenes

The previous step of this tutorial has demonstrated the basic steps to display avatars for all users attending a scene. However there is still a flaw with it: If a user enters a scene, the avatars of other users will not become visible untill they move. This step modifies the scripts in a way that avatars are shown correctly already initially.

In fact the avatars are displayed, they are just at zero position, which is inside one of the houses. The reason for this is that we do not send them an initial position.

Sending the initial position to the avatar looks simple at first sight, but we must take into account that we may load the avatar from a webserver and this may take some while untill the avatar geometry is available. Therefore we must assign the initial position in the function AvatarLoded(.), which is executed on reception of the avatar geometry.

Also, it may happen that the AvatarInfo node receives a position update before the avatar has been received from the web server. In that case the AvatarInfo node should store the position for later, rather than forwarding it to the non-existing avatar.

In order to have a clearer interface, we move the initialization code from the set_avatarString to a separate Init event. This way we can first set all parameters like avatar string, initial position and orientation and then trigger initialization of the AvatarInfo node.

The set_position(.) and set_orientation(.) functions are therefore governed by the following code:

    // send it to the avatar.
    // store it for later.
    InitialPosition= Pos;

... and the AvatarLoaded(.) function assigns the value stored in InitialPosition to the new avatar and sets bHaveAvatar to true, so that the next time set_position(.) and set_orientation(.) receive an update they can send the value directly to the avatar.