Question by
LucianoAdvenio · Feb 17, 2016 at 03:33 PM ·
rotationclamplever
Clamp Lever Rotation
I have the following script:
private float _originalRotationX;
private float _startPosition;
private float _position;
public float _speed = 0.3f;
private float _minRotation = -50f;
private float _centerRotation = 0f;
private float _maxRotation = 50f;
private float _leverLevel;
public delegate void DLGNotifyValue(float value);
public DLGNotifyValue notifyDLG;
private Transform tf;
void Start()
{
tf = GetComponent<Transform>();
tf.localEulerAngles = Vector3.zero;
}
public void InputPressed()
{
_originalRotationX = tf.localEulerAngles.x;
_startPosition = Input.mousePosition.y;
}
public void InputDragged()
{
_position = Input.mousePosition.y;
float posDiff = _position - _startPosition;
tf.Rotate(Vector3.right * posDiff * _speed);
_startPosition = _position;
_leverLevel = (tf.localEulerAngles.x / (_maxRotation - _minRotation));
if (notifyDLG != null)
{
notifyDLG(_leverLevel);
}
}
}
It is attached to this lever:
The problem is that I don't know how to use Mathf.Clamp because in up direction it has a [0º, 50º] range and in down direction it has a [0º,-50º] or [360º, 315º] range. I don't want to rotate the lever pivot in 3ds max. I want to know if it is posible to clamp the value in different ranges.
Thank
Comment
Your answer
Follow this Question
Related Questions
Mathf.Clamp Negative Rotation for the 10th Million Time 1 Answer
Clamping a Quaternion Euler 0 Answers
Problem with Clamping Mous Y input 0 Answers
Object don't rotate correctly 1 Answer
Cannon rotation clamping 0 Answers