Character Controller over the network

Options
I'm using PUN and I am having trouble maintaining character control whenever two clients are connected to the server.

When one client is connected, everything works as intended. When the second client connects, for some reason, their controls switch.

I think the problems lies in my hierarchy design rather than the code itself, here are the paste bins to the two scripts any way.

Player Movement: https://pastebin.com/ntTCXP8Y
Mouse Look: https://pastebin.com/FR0Tmkhy

In my scene I have a GameManager.cs script attached to an empty object.

This script has the player prefab added to the correct spot in the inspector for 'public GameObject playerPrefab'

Here is where I think the problem lies: The player prefab has the main camera attached to it as well as an audio listener. while the arena has only one player in it, movement works as intended.

As soon as player 2 joins, a new player prefab spawns with a new main camera and audio listener, the console displays the "there are 2 audio listeners in the scene" error and suddenly player 1 now controls player 2 and vise versa. Both mouse look and movement.

I don't exactly understand why this problem is occurring, and don't seem to understand at all how to fix it. Any input or direction would be appreciated.

Comments

  • Nazca
    Nazca
    edited January 2021
    Options
    Its worth mentioning that the player prefab is located within the correct "Resources" folder as well.
  • Nazca
    Options
    Does any one have any input at all?