Hi, I’ve been trying to get a function working to snap rotation of a block on each axis to increments of 90 degrees. The problem I’ve been having is that, no matter how I seem to approach applying rotation, I get slight miscalculations at certain rotations.

The code:

```
void RotateBlock()
{
if (buildMode == BuildMode.Active)
if (!IsACube())
{
float xAngle = 0;
float yAngle = 0;
float zAngle = 0;
if (Input.GetKeyDown(KeyCode.G))
xAngle = 90f;
if (Input.GetKeyDown(KeyCode.R))
yAngle = 90f;
if (Input.GetKeyDown(KeyCode.F))
zAngle = 90f;
if (mirrorMode == MirrorMode.Inactive)
{
tempBlock1.transform.Rotate(
Mathf.RoundToInt(xAngle),
Mathf.RoundToInt(yAngle),
Mathf.RoundToInt(zAngle),
Space.World);
}
else
{
tempBlock1.transform.Rotate(
Mathf.RoundToInt(xAngle),
Mathf.RoundToInt(yAngle),
Mathf.RoundToInt(zAngle),
Space.World);
tempBlock2.transform.Rotate(
Mathf.RoundToInt(xAngle),
Mathf.RoundToInt(-yAngle),
Mathf.RoundToInt(-zAngle),
Space.World);
}
}
else return;
}
```

On -90 and +90 rotations for each axis, I’m getting a deviation of -/+ 0.00001 which is causing me problems elsewhere because I need to be able to check an object’s rotation against a vector. I’m also getting a weird assignment (-1.525879e-05) to the Y and Z axes every other time the X rotation snaps to -180.

I’m sure I’m just doing something stupid, but I’m at a loss as to what. Any help would be hugely appreciated. For the record, I’ve tried each of the angles being an int, rounding the rotational assignment with Mathf.Round, Mathf.RoundToInt, or without any rounding at all.