Why is my rotating camera "bouncing?"

The setup: I have an overhead, downward-angled camera that can rotate around your character in 45 degree increments. It works, but for some reason the camera’s Y position is slightly increasing and then decreasing again as it reaches its new position. This causes a noticeable “bounce,” particularly in the background where a change in height is more apparent.

I’m relatively new to Unity, and entirely new to posting on Answers, so bear with me here.

Here’s the relevant parts of the code:

	void Update ()
		{
		if (Input.GetAxisRaw("RotateCamera") != 0 && transform.position == moveTo)
			{rotateCamera();}
		}
	
	void LateUpdate ()
		{
		maintainCameraOffset();
		
		if (transform.position != moveTo)
			{
			transform.position = Vector3.MoveTowards(transform.position, moveTo, rotationSpeed * Time.deltaTime);
			if (Vector3.Distance (transform.position, moveTo) < .0001)
				{
				transform.position = moveTo;
				}
			}
		
		transform.LookAt (target.transform);
		}
	
	public void rotateCamera()
		{
		if (Input.GetAxisRaw("RotateCamera") > 0)
			{
			Vector3 originalPosition = transform.position;
			transform.LookAt(target.transform.position + (Vector3.up * vDistance)); //Look parallel to ground to prevent it from adding more height
			transform.RotateAround(target.transform.position, Vector3.down, 45);
			moveTo = transform.position; //Store the eventual resting place
			transform.position = originalPosition;
			transform.LookAt(target.transform.position);
			}
		
		//Same thing in reverse for the other direction.
		}

Not sure if you are still having this issue (been a few days), but I believe the problem is not that your camera’s Y is increasing and then decreasing, it is that when you are moving towards your new moveTo position with Vector3.MoveTowards, you are moving in a straight line as apposed to a spherical arc. So, your camera’s position starts off at a certain distance from the target, then gets progressively closer to the target as it moves to the midway point, then goes back to the original distance finally at moveTo.

The effect of this is that your camera’s pitch angle changes as you keep looking at the target, so giving the illusion that the camera is increasing in hight (which would also cause a pitch angle change). Thus making the camera look like it is bouncing during the rotation.

There are, of course, many ways to do an orbit camera, but something like the following would provide the type of behavior you want I think. Wasn’t sure how you wanted to initialize your camera, from some predefined horizontal and vertical distance from the target - or if you wanted it to initialize with the camera’s relative position to the target at startup. The below will do the latter:

	public float rotationSpeed = 45f;
	public GameObject target;
	private float vDistance;
	private float hDistance;
	private float currentAngle;
	private float targetAngle;
	
	void Start()
	{
		vDistance = transform.position.y - target.transform.position.y;
		transform.position += Vector3.down * vDistance;
		hDistance = Vector3.Distance(transform.position, target.transform.position);
		currentAngle = Quaternion.LookRotation(transform.position - target.transform.position).eulerAngles.y;
		targetAngle = currentAngle;
	}
	
	void Update ()
    {
		if (Input.GetAxisRaw("RotateCamera") != 0 && currentAngle == targetAngle)
			{rotateCamera();}
		
		currentAngle = Mathf.MoveTowards(currentAngle, targetAngle, rotationSpeed * Time.deltaTime);
		
		transform.position = target.transform.position + Quaternion.Euler(0, currentAngle, 0) * Vector3.forward * hDistance + Vector3.up * vDistance;
		transform.LookAt (target.transform);
    }
 
    public void rotateCamera()
    {
		targetAngle += Input.GetAxis("RotateCamera") > 0 ? 45 : -45;
    }