Oribiting Camera Around Player/Object

I watched the basic tutorial on Quaternion and thought the orbiting example seemed simple enough I can implement it for my game. I know it only goes in one direction, but I’m trying to first figure out why it isn’t facing the player to begin with!

			Vector3 relativePos = (PlayerTransform.position + new Vector3(0, 1.5f, 0)) - Camera.main.transform.position;
			Quaternion rotation = Quaternion.LookRotation(relativePos);

			Quaternion current = Camera.main.transform.localRotation;

			Camera.main.transform.localRotation = Quaternion.Slerp (current, rotation, Time.deltaTime);
			Camera.main.transform.Translate (0,0,3 * Time.deltaTime);

Seems simple enough. It orbits the player fine, but it doesn’t face the player! I tried changing the rotation of the camera in the Editor but regardless of it’s start position it won’t face the right object.

Any ideas?

Unfortunately, that’s not how slerp (or lerp) works.

If you want a camera to look at something, specifically, it’s usually easiest to use transform.LookAt:

void Start() {
    //start position: behind the player
    Camera.main.transform.position = PlayerTransform.position - PlayerTransform.forward * 3f + PlayerTransform.up;
}

void Update() {
    //move right and face the player
    //we will naturally orbit, because our definition of "right" changes each frame
    Camera.main.transform.Translate(Vector3.right);
    Camera.main.transform.LookAt(PlayerTransform.position);
}