How to set up in multiplayer a camera for each player?

Updated on March 4, 2018 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on March 4, 2018

When I move host the camera works fine, but if I move the client, the camera doesn’t follow him, but if I move the host again, then the camera on client moves just like the host’s camera.

NoRotationCamera script:

int DistanceAway = 6;
void FixedUpdate()
 {
 Vector3 PlayerPOS = GameObject.FindWithTag("Player").transform.transform.position;
 GameObject.Find("Main Camera").transform.position = new Vector3(PlayerPOS.x, PlayerPOS.y + 14, PlayerPOS.z - DistanceAway); 
 }

PlayerController script:

 public override void OnStartLocalPlayer()
 {
 GetComponent<NoRotationCamera>();
 }
  • Liked by
Reply
0 on March 4, 2018

Instead of using FindWithTag(“player”) to assign the player to the camera, you should instantiate a camera for each player prefab, and make it follow only the one it was instantiaded for

  • Liked by
Reply
Cancel