# Can rotation be clamped when X produces -30 for both negative and positive?

I am creating a basic Puzzle Bubble clone, however I’m having some issues with the rotation of the cannon.

It points correctly towards the touched position - or drag, however also rotates past the stage. The rotation takes place on the X variable, but produces -30 for both directions, facing up from the bottom.

``````        Vector3 difference = mainCamera.ScreenToWorldPoint(TouchLocation) -
LauncherObject.position;

difference.Normalize();
float rotateX = Mathf.Atan2(-difference.y, -difference.x) * Mathf.Rad2Deg;
Vector3 TargetAngle = new Vector3(rotateX, -90, -90);
LauncherObject.rotation = Quaternion.Euler(TargetAngle);
``````

What would be the correct way to clamp this, when the two values are -30, 90, 90 and -30, -90, -90?

Is this what you are looking for?

``````// this will clamp the vectors points to +/- the respective clamp values
Vector3 clamp = new Vector3(30, 90, 90);
for (int i = 0; i < 3; i++)
{
float point = TargetAngle*;*
``````

TargetAngle = Mathf.Min(clamp_, Mathf.Abs(point)) * Mathf.Sign(point);
}_