- Home /
How would I clamp a balance board? Mathf.clamp does not work!
I've gotten a balance board ALMOST working. However... the mouse controls for it aren't really cooperating right, and I need to clamp them. I tried a Mathf.Clamp and ran into an immediete problem: From 90 degrees pointing up, both directions equal -80 at the points I want to clamp. No negative or positive, just -80, -80.
Vector3 MouseImpactPoint = GameController.Instance.RawRayPosition;
Vector3 RotateTowards = new Vector3(-(Mathf.Atan2((MouseImpactPoint.x - TiltBed.transform.position.x), (MouseImpactPoint.y - TiltBed.transform.position.y))*Mathf.Rad2Deg - 90), 90, -90);
Debug.Log(RotateTowards);
Quaternion Rot = Quaternion.identity;
Rot.eulerAngles = RotateTowards;
TiltBed.transform.localRotation = Rot;
Have a look at @aldonaletto's answer on this other topic and see if that will help you :
http://answers.unity3d.com/questions/141775/limit-local-rotation.html
Solved it! Hate to say but none of the answers turned out to work right. Ins$$anonymous$$d, I clamped the controls. Clamping the movement range... severely messed up the design of the balance. Thankfully my input control is intentionally designed to be generic to take multiple types of control.
Answer by Julien-Lynge · May 22, 2014 at 05:14 AM
Instead of Mathf.Clamp, look at Mathf.Maximum. That's how you can 'clamp' in only one direction.
Unfortunately $$anonymous$$athf.$$anonymous$$ax seems to just lock it into one place and it refuses to move.
//RotateTowards.x = $$anonymous$$athf.$$anonymous$$ax(-78.5f, -81.4f);
Your answer