A hard clamp.. Clamp Rotation 340-0-14

I find my self it with a problem that i’ve been attempting to solve for a few hours now. I am trying to clamp a rotation range of what is essentially 340-360 degrees(or you could say 340-0 degrees) and 0-14 degrees. The problem is… Since the rotation clamp i am trying to implement has 0 at the center i’m not sure how to handle it because using: transform.localEulerAngles = Vector3(Mathf.Clamp(transform.localEulerAngles.x,0,340),0,0); is saying you can move 340 degrees from 0. What i need it to be is 340-360 and again from 0 - 14. If it were all above 0… say 20-60 this would be no problem.

Sorry if i’m babbling… i’m just perplexed.

var x=transform.localEulerAngles.x;
if(x > 180) x-=360;
x=clamp(x, -20, 14);

x=clamp(x, -20, 14);

is “clamp” a separate function or short for Mathf.Clamp? I don’t see what clamp by it’s self is…

Got it working. Thanks so much for pointing me in the right direction.

x = transform.localEulerAngles.x;
x=ClampAngle(x, -20, 14);

}

function ClampAngle (x : float, min : float, max : float) {

	if (x > 180) {
		x -=360;
	}
	Debug.Log(x);
	return Mathf.Clamp (x, min, max);
}