Hey guys, how do you clamp an euler angle?
I have this.
// Called on every frame. Handles touch data and rotates Cube.
void Update()
{
int fingerCount = 0;
Vector3 CurrentFingerPos;
foreach (Touch touch in Input.touches)
{
if (touch.phase != TouchPhase.Ended touch.phase != TouchPhase.Canceled)
{
fingerCount++;
}
if (fingerCount > 0)
{
if(fingerCount > 0 fingerCount < 2)
{
CurrentFingerPos = touch.deltaPosition;
// Sets our finger movement to object rotation.
if(Vector3.Dot(transform.forward, new Vector3(0.0f,1.0f,0.0f)) < 0.5)
{
z += CurrentFingerPos.x * speed;
}
else
{
z -= CurrentFingerPos.x * speed;
}
y += CurrentFingerPos.y * speed;
x = 0;
// Converts our numbers into euler angles.
Quaternion rotation = Quaternion.Euler(y, x, z);
// Sets our new rot.
transform.rotation = rotation;
}
}
else
{
return;
}
}
}
It works… I’m trying to make it so that whatever way the object is facing… whether upside down or rightside up, when you move your finger right, it will still spin right… The thing is that that suddenly the controls will ‘jump’ to moving the other way, really confusing you.
Is there a way to lock the Y axis so it doesn’t pass 180 degrees?
Thanks