I’m new to multiplayer thing, I am struggling with player prefab. I have player prefab in my assets and I am trying to spawn player like three or four. The thing is I use cinemachine camera config and I also want to make camera follow along the player. I tried to parent camera to the player in prefab. But when I spawn two player prefabs, the error occurs that mouse positioning is controlling both players. And i Spawn with netcode.
One way to do this is to have a check on the script of each player object that checks for IsLocalPlayer
in OnNetworkSpawn
. If it’s not the local player object, then disable the camera and do not accept input from the player. That way, each player only sees the camera on their local player object and is only able to control that player.
I split up my player prefab into a local and remote part. Depending on whether IsLocalPlayer I disable one of these two trees, thus the remote player will not have a camera or respond to input, while the local player isn’t seeing his floating-above-head name tag when looking up.
It’s not best practice to make the vcam a child of the player. Instead, if you want to include a vcam in the prefab, make it and the player both children of a common parent object.
You can have the vcam inactive by default, an activate it only if you are spawning the local player.
Was wondering about that actually because most examples had it outside of the character’s hierarchy. I just moved it in there to see if it would work, and it did. What can be some issues of having the vcam as a child?
I am now making this in that way and try to disable the objects for non-local players. Do you have any advices or advancements through the process may I ask?