Trying to make camera align characters horizontally

I’m trying to have the camera align the player character and the target horizontally in relation to the camera. What I made works, but the player is always on the left side. I want to make it so the player can be in either the left or right side.

This is my code:

 Vector3 targetAngleDir = target.position- player.position;
    		targetAngleDir.y = 0;
    		targetAngleDir.Normalize();
    
    		float targetAngle = Quaternion.Angle(transform.rotation,Quaternion.LookRotation(targetAngleDir));

    transform.localRotation= Quaternion.Euler(new Vector3(0,transform.localRotation.eulerAngles.y,0));

    transform.Rotate(30,(targetAngle - 90) * Time.deltaTime,0);

I tried changing the last line to

		if(Mathf.Abs(targetAngle-90) < 90){ 
			transform.Rotate(30,(targetAngle-90) * Time.deltaTime,0);
		} else {
			transform.Rotate(30,((180 * Mathf.Clamp(targetAngle-90,-1,1))-(targetAngle-90)) * Time.deltaTime,0);
		}

but it didn’t change anything

I managed to get it working and it was easier than I expected, I was just going about it the wrong way. I changed the last line to:

if(transform.InverseTransformDirection(targetAngleDir).x > 0){
			transform.Rotate(30,(targetAngle - 90) * Time.fixedDeltaTime,0);
		} else {
			transform.Rotate(30,-(targetAngle - 90) * Time.fixedDeltaTime,0);
		}

and it worked. My character now stays in either the left or right side instead of just the left.