# Rotate camera around ball; always face "back" of ball?

I’m trying to get my camera to rotate around my ball when I turn left and right. I’m using the Update method and:

``````void Update () {
//transform.eulerAngles = new Vector3 (1, 1, 0);
transform.RotateAround(player.transform.position, player.transform.eulerAngles, 0);

}
``````

but the camera just goes all spastic. How can I keep my camera facing the back of my ball as if it were a person and we were always behind the person who is walking?

RotateAround rotates your transform around a point, with regards to an axis, a number of degrees. Read the docs here, there’s a good example.

If you want to keep the camera at a fixed position and rotation with regards to the player character, @Hellium’s comment is the best bet - make the camera a child of the player, and skip the scripting. If that’s not viable, this is a super-cheap implementation:

``````float cameraVDistance = 10f; //how far the camera is behind the player
float cameraHDistance = 5f; //how far the camera is above the player

void Update() {
Vector3 playerPosition = player.transform.position;

Vector3 behindPlayer = -player.transform.forward * cameraVDistance;
Vector3 abovePlayer = Vector3.up * cameraHDistance;

Vector3 cameraPosition = playerPosition + behindPlayer + abovePlayer;

Vector3 cameraToPlayer = playerPosition - cameraPosition;
Quaternion cameraRotation = Quaternion.LookRotation(cameraToPlayer);

transform.position = cameraPosition;
transform.rotation = cameraRotation;
}
``````

That’s put the camera behind the player, looking at the player. You’ll want to mess with the values somewhat, and the camera should probably be looking at a point a bit above the player (so you don’t just see mostly ground), but that’s a quick start.

Honestly, childing the camera to the player character is easier, but there you go.