Step 8 — Displaying the own avatar

The previous step demonstrated how to display an avatar for all other users. Here we learn how to make BS Contact display the right avatar for View-my-Avatar mode.

BS Contact can operate in First-Person mode as well as in Third-Person mode. First-Person mode is on by default. No avatar is displayed for the local user and the scene is presented to the local user from the position of the avatar. This way the user sees what his/her avatar "sees". In Third-Person mode an avatar is displayed for the local user and the scene is rendered from a point behind the avatar, so that the user can see their own avatar. The user can switch between both modi with the "View my Avatar" menu entry on the right-click menu.

Previous steps of this tutorial just ignored the hasJoined event if it was for the local user. This is indicated with a zero index in the UserData node. In this step, rather than ignoring the event, we just treat it slightly different. Instead of adding it to the visible scene graph we pass it to BS Contact so that BS Contact can display it when in Third-Person mode.

Unlike previous steps of this tutorial we add a flag isLocal to the AvatarInfo node and set it if the index in the UserData node is zero. The ScrAvatarMgr script also refrains from adding the newly created AvatarInfo node to the Group GrAvatars in that case, so that the avatar is not displayed.

The AvatarInfo node forwards the flag to the avatar if it has such an eventIn, and calls the Browser.setMyAvatar(.) function if the flag is true. This function tells BS Contact about which avatar to display in Third-Person mode.

To switch between Third-Person mode and First-Person mode programmatically a script can use the function Browser.showMyAvatar(.) or Browser.setThirdPersonView(.), which are synonyms.