# A smooth camera follow that allows for rotation functionality independent of the player. Maths?

I have a camera that is looking at a player object at a 45 degree angle on a key press. As of now the rotation around the player works great.

The problem lies when I try to add a smooth camera follow at that 45 degree angle, because as the rotation changes, the follow coords change, and it gets a little wonky. Any of the typical camera follow methods I have used seems to have failed, I believe there is some fancy math work here that is beyond me,that or I’m overlooking something simple… Any help would be hugely appreciated!

Here is the code for the camera as of now:

``````    public GameObject targetObject;
private float targetAngle = 0;
const float rotationAmount = 1.5f;

// Update is called once per frame
void Update()
{

if (Input.GetKeyDown(KeyCode.Q))
{
targetAngle -= 90.0f;
}
else if (Input.GetKeyDown(KeyCode.E))
{
targetAngle += 90.0f;
}

if (targetAngle != 0)
{
Rotate();
}
}

protected void Rotate()
{

if (targetAngle > 0)
{
transform.RotateAround(targetObject.transform.position, Vector3.up, -rotationAmount);
targetAngle -= rotationAmount;
}
else if (targetAngle < 0)
{
transform.RotateAround(targetObject.transform.position, Vector3.up, rotationAmount);
targetAngle += rotationAmount;
}

}
``````

Not sure if i understand correctly but what you could do is have an empty gameobject with a script that updates its position in the update function to that of the player.Then child the camera to that object instead of the player.

EDIT: On my way to work so thats why im keeping it short! Be carefull to keep the target of your camera script to that of the player and not the newly created object.