I’m creating a turn based game set in space in which two teams of players are on opposite sides of a three-dimensional playing field. The white team and black team begin the game with the same orientation, except that the white team is rotated 180 on the Y axis and also rotated 180 degrees on the X axis (meaning the two teams are facing each other and one team is upside down).
To make play even between turns, I need the camera to perform a complex rotation so that both players can control their own team from the same perspective on their turn. My goal is to have either player, at the beginning of his own turn, facing toward the right side of the screen with his head up toward the top and his feet down toward the bottom. My goal is to make a smooth camera rotation from (0,0,0) to (180, 0, 180) or (0, 180, 180), and then make it go back when the turn changes again.
I am not having a problem changing the position of the camera so that it points at the correct team, but I am having trouble with the rotation.
In attempting to solve this problem, I have created a focal point around which the camera orbits. When a turn change begins, the variable slerpOnBlack or slerpOnWhite turns to true. As long as this variable is true, one of the following two methods will fire on every update:
void SlerpCameraBlack(){
if (new Vector3(CameraFocus.transform.rotation.x, CameraFocus.transform.rotation.y, CameraFocus.transform.rotation.z) != new Vector3(0, 0, 0)) {
CameraFocus.transform.rotation = Quaternion.Slerp (CameraFocus.transform.rotation, Quaternion.Euler(new Vector3(0, 0, 0)), (10*Time.deltaTime));
} else {
SlerpOnBlack = false;
}
}
void SlerpCameraWhite(){
if (new Vector3(CameraFocus.transform.rotation.x, CameraFocus.transform.rotation.y, CameraFocus.transform.rotation.z) != new Vector3(0, 180, 180)) {
CameraFocus.transform.rotation = Quaternion.Slerp (CameraFocus.transform.rotation, Quaternion.Euler(new Vector3(0, 180, 180)), (10*Time.deltaTime));
} else {
SlerpOnWhite = false;
}
}
Use of these functions results in inconsistent results which I do not understand, and which lead me to believe that I must not understand clearly how to use quaternions.
Can anyone help me resolve this?