// Aim at the target (up and down).

Vector3 dir = hit.point - barrel.position;

Quaternion lookRotation = Quaternion.LookRotation(dir);

Vector3 rotation = lookRotation.eulerAngles;

rotation.x = Mathf.Clamp(rotation.x,-15,90);

barrel.rotation = Quaternion.Euler(rotation);

As you can see that code is quite simple, the goal is to clamp the x axis (so the barrel can look up and down at a specific range).

Well it works, however, for some reason when the x Axis reaches roughly 0.0157f it clamps it to positive 90 instantly (which is looking down) and this happens when I try to reach -15 (which is up).

Down work fine, but I can’t for some reason get past the 0 decimal range when getting into the negatives (looking up rotation).