So, I made a platform rotate around the x and z axis and that works fine. Then I decided I should put a clamp on how much the platform can rotate. The problem is that the rotation of the transform.x and transform.z don’t become a negative one way and a positive the other (ex: Rotation x:10 y: 0 z: -10). In on direction the rotation counts up starting from 0 and the other direction on the same axis it counts down starting from 360, obviously this is because there are 360 degrees in a full rotation (ex: Rotation x:10 y:0 z:350). I mean it is still the same amount of degrees in each direction but I can’t clamp it the same way as with position because when I clamp it the rotation has to be between those two values, but with this the max and min rotation isn’t between the two values its between two values on either side of 0 and 360! So what do I do to fix this?
#pragma strict
var xMin: float; //variables used for boundaries of rotation
var xMax: float;
var zMin: float;
var zMax: float;
function FixedUpdate ()
{
var rotateLR: float = Input.GetAxis("Horizontal"); //used to grab input from axis controls and translate into movement
var rotateFB: float = Input.GetAxis("Vertical");
transform.Rotate(rotateFB, 0.0f, rotateLR * -1, Space.World); //how exactly to rotate the platform
transform.rotation = Quaternion.Euler //the boundary to where the platform should stop rotating
(
Mathf.Clamp(transform.rotation.x, xMin, xMax),
0.0f,
Mathf.Clamp(transform.rotation.z, zMin, zMax)
);
}