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