# Make a camera follow and rotate around two playera

I have the script of rotation around and following for one player. How should i change it so that it follows two players and revolves around them

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerFollow : MonoBehaviour {

public Transform PlayerTransform;

private Vector3 _cameraOffset;

[Range(0.01f, 1.0f)]
public float SmoothFactor = 0.5f;

public bool LookAtPlayer = false;

public bool RotateAroundPlayer = true;

public float RotationsSpeed = 5.0f;

// Use this for initialization
void Start () {
_cameraOffset = transform.position - PlayerTransform.position;
}

// LateUpdate is called after Update methods
void LateUpdate () {

if(RotateAroundPlayer)
{
Quaternion camTurnAngle =
Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);

_cameraOffset = camTurnAngle * _cameraOffset;
}

Vector3 newPos = PlayerTransform.position + _cameraOffset;

transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);

if (LookAtPlayer || RotateAroundPlayer)
transform.LookAt(PlayerTransform);
}
}
``````

``````    void Update()
{
direction = (PlayerTransform02.position - PlayerTransform.position).normalized;
distance = Vector3.Distance(PlayerTransform.position, PlayerTransform02.position) * 0.5f;
focus.position = PlayerTransform.position + (distance * direction);
// follow "focus", rotate around "focus"
}
``````

untested so you may need to invert a value, but this is basically what you want to do. follow and rotate around a point between them. easiest way is to just offset the third point -from- the player position -towards- second players position -by- half of their distance

You just need to get the direction:

``````Vector3 direction = playerTwo.transform.position - playerOne.transform.position;
``````

That contains the direction in world space and the length of the vector that extends between the 2 positions. Now multiply by 0.5f to get the midway point between the 2 positions and add it to the player one position:

``````Vector3 pivotPoint = playerOne.transform.position + (direction * 0.5f);
``````

That is your mid point. Get your camera to focus on that

Thank you all very much it works beautifully!