Top-down multiplayer camera follow

So I am currently working on a top down shooter game, and am able to get the camera to follow a single player top down character. But Im not sure how to set up the camera so that i follow the player. Note that I cant just make the camera a child of the player object as it will cause the character to spin out of control. So how would I be able to make the characters have a camera follow them from above like Dead Frontier AND be able to have each player have their own camera?

  1. Create a parent “PlayerGOs” gameobject.
  2. Under the gameobject, create your player and a camera.
  3. Do NOT parent the camera to the player object, they should be separate, but following the “PlayerGOs” transform.
  4. Create a script on the camera to have the identical position as the player, but add a y-offest of however much you’d like (10-20 units or so).

Something such as:

    void cameraFollow()
    {
        float charPosX = transform.position.x;
        float charPosZ = transform.position.z;
        float cameraOffset = 18.0f;

        viewCamera.transform.position = new Vector3(charPosX, cameraOffset, charPosZ);

    }

This script would be placed on the Player gameobject, and reference the camera (doing it publically is likely the easiest). You would also need to call this function every frame in Update or LateUpdate.

void Update (){
    cameraFollow();
}

To make sure each player has their own camera in a multiplayer setting, this is a little more complicated, but you’ll basically instantiate this PlayerGOs object as the ‘player prefab’ in your network manager. After that, each script should check if it belongs to the local player, and if not, delete or disable. Such as:

void Update () {

        if (!isLocalPlayer)
        {
            gameObject.SetActive(false); //can probably be done more efficiently so not being called redundantly every frame
            return;
        }

That’s how I do it at least, and it works well with no CPU overhead for me.

Cheers.
Vranvs