Different Humanoids for Networked Players
In the introductory video for networking with Humanoid Control, all players have the same avatar. But in most cases you want players to look different from each other. This article describes how you can do this.
The article describes two different solutions:
- A build for each type of player
- Choosing the Avatar at Runtime
A build for each type of player
Suppose you want to have two types of players in your setup:
- A guide who has extended abilities like operating user interfaces and
- Visitors who can primarily look around.
The way to achieve this is to build the whole scene with two Humanoids inside: one for each type of player.
Both Humanoids should be configured normally as a normal player with a First Person Camera and SteamVR, Oculus and/or Mixed Reality support. But you can also configure the differences between the Humanoid now. The guide could have Physics and Touch Interaction on the Hand Targets for example.
Finally, the NetworkingStarter prefab should be added to the scene to add networking support. If you get errors on a missing script, you should check if Networking Support is enabled in the Edit Menu->Preferences->Humanoid.
In the example below, Robot Kyle is considered the visitor, while the Humanoid is the guide.
For each build, we then need to change two settins:
For this build, we need to disable the visitor humanoid so that only the guide remains.
As the guide will be the first in the setup, we also choose this build to be the Host for networking. This means that it includes the server to which all other players connect. So we set the Role to ‘Host’ in the Netrworking Starter script:
Now we can make the guide build by choosing File Menu->Build Settings->Buils.
For the visitor, we do the opposite. We disable the guide humanoid in the scene:
In the NetworkingStarter component, we choose the ‘Client’ role and set the Server IP Address to the address of the machine on which the guide/host will be running:
Then we can make the visitor build using File Menu->Build Settings->Build.
After this you will have two builds: one for the guide with a special avatar and abilities and one for the visitors who are showed around by the guide.
Choosing an Avatar at Runtime
For this solution we use the Avatar Manager component which is included in the Humanoid Control package.
The Avatar Manager component should be added to a Humanoid in the scene. You can configure the Avatar Manager with the available avatars for that humanoid:
Optionally, you can also choose a Third Person avatar which will be used at remote clients.
At startup, the avatar selected by the Current Avatar Index will be used. Then you can use one of the function methods on the avatar to choose a different avatar:
- SetAvatar(int avatarIndex) will change the avatar to the one indicated by the index parameter,
- NextAvatar will choose the next avatar in the list in a round-robin manner,
- PreviousAvatar will choose the previous avatar in the list in a round-robin manner.
In this way you can change the avatar at runtime and have many different avatar for the players.