I’m making a game where the player can rotate a platform. However, I don’t want the player to be able to rotate the platform completely around. To prevent this I attempted to add if statements that would check the current value of the platforms angle, and if the angle was more or less than a specific angle it would continue to rotate when a specific key is being pressed. I understand that a negative angle isn’t technically a thing but Unity’s transform inspector shows a negative angle rather than passing 180 degrees. Is there a way to call that number rather than a number from 360? If not then might someone have an alternate suggestion on how to proceed with my goal?
Here’s an example of the code I’m using.
void Update()
{
if (Input.GetKey(KeyCode.W))
{
if (gameObject.transform.rotation.eulerAngles.x < 20)
{
transform.Rotate(0.5f, 0, 0);
}
}
if (Input.GetKey(KeyCode.S))
{
if (gameObject.transform.rotation.eulerAngles.x > -20)
{
transform.Rotate(-0.5f, 0, 0);
}
}
}