r/UnityHelp • u/[deleted] • Jun 17 '23
How does this even happenng?
I'm new to unity and trying to set minimum camera rotation X angle (90), and maximum (-90)
(according to the scene editor this is what I need):
private float maxXAngle = -90;
private float minXAngle = 90;And I wrote this code:
if (rotation.x < maxXAngle)
{
Quaternion currentRotation = transform.rotation;
Quaternion newRotation = Quaternion.Euler(maxXAngle, currentRotation.eulerAngles.y, currentRotation.eulerAngles.z);
transform.rotation = newRotation;
}
if (rotation.x > minXAngle)
{
Quaternion currentRotation = transform.rotation;
Quaternion newRotation = Quaternion.Euler(minXAngle, currentRotation.eulerAngles.y, currentRotation.eulerAngles.z);
transform.rotation = newRotation;
}And the results is:
when rotation.x > 180 it sets the rotation on X to 90
and when rotation.x < 0 it sets the rotation on X to 90 too.
I've been messing with this for about 2 hours and still could nor fix this so please help!
2
Upvotes
1
u/MischiefMayhemGames Jun 17 '23
This is just the result of a quick glance but (assuming rotation is a Quaternion) I think you want
in your if statement not