Check if character rotation is 180 degree turn
I've been struggling with this issue for a while now and I have no idea how to fix it.
I want to check if my character would turn 180 degrees and if it would, then don't turn. So basically only make it turn 90 degrees. the solution i tried works perfectly when i press a button on the vertical axis but for some reason it doesn't want to work on the horizontal axis whatever I try.
This is the code I have. on the horizontal axis the angles when left and right is -90 and 90 and on the vertical axis it's 0 and 180.
If anyone could help me in any way... I am out of ideas on how to fix it.
if( horizontalInput==1 )
{
//-90 & 90
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
if (controller.transform.rotation.y == 90 )
Debug.Log("180 degree +h turn");
else
{
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
controller.transform.rotation = rotation;
}
}
else if (horizontalInput == -1)
{
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
if (controller.transform.rotation.y == 270)
Debug.Log("180 degree -h turn");
else
{
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
controller.transform.rotation = rotation;
}
}
else if (verticalInput == 1)
{
//0 & 180
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
if (controller.transform.rotation.eulerAngles.y == 180)
Debug.Log("180 degree +v turn");
else
controller.transform.rotation = rotation;
}
else if(verticalInput == -1)
{
Debug.Log("previouslocation" + controller.transform.rotation.eulerAngles.y);
if (controller.transform.rotation.eulerAngles.y <= 0)
Debug.Log("180 degree -v turn");
else
controller.transform.rotation = rotation;
}
replace controller.transform.rotation.y
with controller.transform.eulerAngles.y
Your answer
![](https://koobas.hobune.stream/wayback/20220613061031im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I make an object transform to given position and rotation 2 Answers
Problem retrieving transform.position after parent rotation 0 Answers
Deformation of child object when rotating around a rotatable parent object 0 Answers
How to Stack, Shuffle and deal cards 0 Answers
Transform rotation with an ease 0 Answers