Player positions
In Unity I have a multiplayer VR game where I have an arena or 4-sided table, it is a game that uses , when the game is created the person who created it appears within the game as an avatar, when the others 3 players join and they also have their own avatars, I want to know how I can show an avatar on each side of the table and make it like this in the local view of each player.
3 Replies
Hi @fgamez1020. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To implement player positioning around a table in a multiplayer VR game using Normcore, you can utilize the RealtimeAvatarManager and custom positioning logic. Here's an approach to achieve this:
1. Use RealtimeAvatarManager to handle avatar instantiation:
The RealtimeAvatarManager is responsible for creating avatars for each player in the room RealtimeAvatarManager documentation (https://normcore.io/documentation/realtime/xr/avatars). You can use this to instantiate avatars as players join.
2. Create a custom script to manage player positions:
Implement a script that assigns positions to players as they join. This script should:
- Keep track of available positions around the table
- Assign a position to each player as they join
- Update the local player's view to always see themselves at their assigned position
3. Modify the avatar instantiation process:
Instead of letting RealtimeAvatarManager place avatars automatically, you'll want to control their positions. You can do this by:
- Creating a custom prefab for your player avatar
- Implementing a custom PlayerManager script that handles avatar instantiation and positioning
Here's a basic example of how your PlayerManager script might look:
This script is based on the example from the Creating a Player Controller guide (https://normcore.io/documentation/guides/creating-a-player-controller#making-it-multiplayer), but modified to handle custom positioning.
Remember to:
1. Set up your _playerPositions array in the Unity Inspector with Transform objects representing each position around the table.
2. Implement the CalculateCameraOffset method to ensure each player's camera is positioned correctly relative to their avatar and the table.
3. Adjust the RealtimeAvatarManager settings to prevent it from automatically spawning avatars, as you're handling this manually.
This approach should allow you to position players around the table and ensure each player sees the game from their perspective. You may need to fine-tune the positioning and camera settings based on your specific game layout and requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1053407831916822528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
easy method is to store an array of spawn points and then use clientID to spawn the avatar in that position
simple as this
void Start(){ if(realtimeView.isOwnedLocallySelf) transform.position = spawnPoints[realtime.clientID].position)}