ljarbo
July 16, 2013, 9:17am
1
Hi,
I have a working movement of a camera.
The camera is restricted to rotate between 0 - 85 degrees.
This is accomplished by testing beforehand if the rotation exceed allowed rotation.
My problem is that since the input value may vary, a large motion might get stopped, while a smaller motion is allowed;
Making my motion stagger before hitting max/min value.
Is there any clever way to handle this?
float newAngle = Camera.main.transform.eulerAngles.x - touch.deltaPosition.y/2;
if(Mathf.Ceil(newAngle) < 85.0f Mathf.Floor(newAngle) >= 0)
{
Camera.main.transform.RotateAround(myObj.transform.position, Vector3.right, -touch.deltaPosition.y/2 );
}
ljarbo
July 16, 2013, 9:49am
2
ah, solved it like this:
float newAngle = Camera.main.transform.eulerAngles.x - touch.deltaPosition.y/2;
//Debug.Log("debugAngel: " + newAngle);
//
if(Mathf.Ceil(newAngle) < 85.0f Mathf.Floor(newAngle) > 0.0f)
{
Camera.main.transform.RotateAround(myObj.transform.position, Vector3.right, -touch.deltaPosition.y/2 );
}
else
{
float clampedVal = 0.0f;
if(Mathf.Ceil(newAngle) > 85.0f)
{
clampedVal = 84.999f - Camera.main.transform.eulerAngles.x;
Camera.main.transform.RotateAround(myObj.transform.position, Vector3.right, clampedVal );
}
else if(Mathf.Floor(newAngle) < 0.0f)
{
clampedVal = 0.001f - Camera.main.transform.eulerAngles.x;
Camera.main.transform.RotateAround(myObj.transform.position, Vector3.right, clampedVal );
}
//Debug.Log("This is clampedVal: " + clampedVal);
}