# Move camera around player while facing player

My player has the following hierarchy:

Hero (GameObject)
Model (child of "Hero", centered at 0-0-0)
Camera (child of "Hero")


The camera should be allowed to

- change its position around the Model in a circle ("rotate around the
center")
- rotate so that it always faces the Model
- move up and down
- move nearer and further from / to the Model


I know how to do that using Quaternions, but as I'm doing this in a coroutine and using Lerp, I found myself in situations where the camera would get right through the model as this was the shortest path between the destination and the target vector.

I would now like to use pure angles (Sin and Cos), preferrably without LookAt. Can somebody share how I would position and rotate the camera according to the angle, perhaps even taking a camera height variable into account as the camera should also be able to move up and down, still facing the player?

That would be the bomb!

Have normalized vector from hero towards camera. Rotate the vector. Place camera at multiplied vector by range(distance). Rotate camera towards hero. Basically rotation around is placing object at the same distance but moving that object in some direction.

Transform.RotateAround

Basically point - is hero position, axis is usually up, if your hero is in vertical position, and angle.

Camera.transform.RotateAround(hero.position, Vector3.up, rotationAngle * rotationSpeed);


Result reference - basically this is how I made planets rotate around star. You can access the whole project via link under video.

public void RotateAround(Transform transform)
{
this.transform.RotateAround(transform.position, this._rotationAxis, this._rotationSpeed);
}

private void Update()
{
this.RotateAround(this._star);
}

private void Awake()
{
this._rotationAxis = Quaternion.Euler(0f, 0f, 90f) * (this.transform.position - this._star.position).normalized;
}


If you want to do it manually you can just store rotation angle, and change it. Using this method you can calculate the vector. Though, it's more for Top-Down, you will have to modify the method to suit your needs.

public static Vector3 GetDirectionFromAngle(float angleInDegrees, float localRotationAngle = 0)
{
angleInDegrees += localRotationAngle;

• @tmighty zoom - you change the range of the camera, you can make it work with RotateAround (it's basically the same thing that doing this manually, it just makes all the calculations based on parameters). Same can be said for moving up or down, you can both RotateAround on horizontal and vertical axis. Look at how I calculate rotation axis in Awake. Basically you need to figure out how to change the rotation axis along the way when you are rotating vertically and horizontally, order shouldn't matter. – Candid Moon _Max_ Feb 10 '19 at 18:24
• @tmighty About manual approach - I am not very good with math to give a solution right away, it may take a lot of effort and testing to make it work. It would even be harder without RotateAround for me personally. – Candid Moon _Max_ Feb 10 '19 at 18:25