# How Do Camera Follow Mullti Playeres

Hi, i have issue with camera follow multi players, i want when each player selected camera folow that and when one of this players destroy camera not follow them. my script work for just one player

public Transform target;
public float distance = 10.0f;
public float height = 5.0f;
public float heightDamping = 2.0f;
public float rotationDamping = 3.0f;

``````  void Update()
{
if(!target.gameObject.active)
this.gameObject.SetActive(false);
}

void  LateUpdate ()
{
if (!target)
return;

Vector3 followpos = new Vector3(0.0f, height, -distance);
Quaternion lookrotation = Quaternion.identity;
lookrotation.eulerAngles = new Vector3(10f, 0.0f, 0.0f);
Matrix4x4 m1  = Matrix4x4.TRS(target.position, target.rotation, Vector3.one);
Matrix4x4 m2  = Matrix4x4.TRS(followpos, lookrotation, Vector3.one);
Matrix4x4 combined  = m1 * m2;
Vector3 position = combined.GetColumn(3);
Quaternion rotation = Quaternion.LookRotation(
combined.GetColumn(2),
combined.GetColumn(1)
);

Quaternion wantedRotation = rotation;
Quaternion currentRotation = transform.rotation;

Vector3 wantedPosition = position;
Vector3 currentPosition = transform.position;

currentRotation = Quaternion.Lerp(currentRotation, wantedRotation, rotationDamping * Time.deltaTime);
currentPosition = Vector3.Lerp(currentPosition, wantedPosition, heightDamping * Time.deltaTime);

transform.localRotation = currentRotation;
transform.localPosition = currentPosition;

}
``````

What I did in my current game is put all the players in a list, then make the target move to the center point of all the players, I use a loop and calculate the centroid. When a player dies I remove them from the list, if one joins I add them to the list.

i solve issue with bool and playerprefs

in game
public static bool one = false;
public static bool two = false;
public static bool tree = false;
public static int index;
index = PlayerPrefs.GetInt (“playerselect”);
if(index == 0)
one = true;
if(index == 1)
two = true;
if(index == 2)
tree = true;

in camera script
if(PlayerSelectionGame.index == 0)
indexx = 0;
if(PlayerSelectionGame.index == 1)
indexx = 1;
if(PlayerSelectionGame.index == 2)
indexx = 2;
Matrix4x4 m1 = Matrix4x4.TRS(targets[indexx].transform.position, targets[indexx].transform.rotation, Vector3.one);