I have it set exactly to 180 because that is the default rotation that my object has. The original idea is to have a set of IF statements handling 8 different degree angles caused by the following code:
void HandlePlayerMovementandRotation(){
//Case Statements Handling Player Movement and Rotation
if (Input.GetKey(KeyCode.A) == true){
transform.Translate( -4f * Time.deltaTime, 0, 0,Space.World);
//Check if Backward Movement is Enabled
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,90);
}
else{
transform.rotation = Quaternion.Euler(0,0,-90);
}
}
if (Input.GetKey(KeyCode.D) == true){
transform.Translate( 4f * Time.deltaTime, 0, 0,Space.World);
//Check if Backward movement is enabled
if (CharFaceOppositeMovement ==true) {
transform.rotation = Quaternion.Euler(0,0,-90);
}
else{
transform.rotation = Quaternion.Euler(0,0,90);
}
}
if (Input.GetKey(KeyCode.W) == true){
transform.Translate( 0, 4f * Time.deltaTime, 0,Space.World);
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,0);
}
else{
transform.rotation = Quaternion.Euler(0,0,180);
}
}
if (Input.GetKey(KeyCode.S) == true){
transform.Translate(0, -4f * Time.deltaTime , 0,Space.World);
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,180f);
}
else{
transform.rotation = Quaternion.Euler(0,0,0);
}
}
}
void HandleAnglesDuringDiagonalMovement(){
//Expressions Handling angles during Diagonal Movement
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A) == true){
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,45f);
}
else{
transform.rotation = Quaternion.Euler(0,0,-135f);
}
}
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D) == true){
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,-45f);
}
else{
transform.rotation = Quaternion.Euler(0,0,135f);
}
}
if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A) == true){
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,135f);
}
else{
transform.rotation = Quaternion.Euler(0,0,-45f);
}
}
if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D) == true){
if (CharFaceOppositeMovement == true){
transform.rotation = Quaternion.Euler(0,0,-135f);
}
else{
transform.rotation = Quaternion.Euler(0,0,45f);
}
}
}
I forgot to mention, my game is 2D. My character is a sprite pasted on a thin cube mesh. The cube mesh starts at a rotation of 180*. The default rotation is 0* facing the bottom of the screen.