I want to limit the amount of rotation on a look up and a look down movement. Below is my script. It works until the “maxAngleUp” goes lower and lower until I cannot look up anymore. I am not sure what is causing it as I can’t recreate with Debug.Log on my PC-it only does it on my Ipad and Iphone. Due to this necessary constraint demand I am wondering if I should switch to a type of hinge joint and script the user to control the rotation as for some reason what
I am doing is not working:
//var speed : float = 10.0;
var rotateJoystick : Joystick;
//var rotationSpeed : float = 5.00;
var rotationSlowDown : float = 70.0;
private var angle : int=0 ;
var rotation : float = 0.0;
var maxUpAngle : int=20;
var maxDownAngle : int=-8;
function Update ()
{
TurretElevation ();
}
function TurretElevation ()
{
if (rotateJoystick.position.y ==0)
rotation=0;
if (rotateJoystick.position.y>0 )
{
if (angle<=maxUpAngle)
{
rotation = (Time.deltaTime*rotation + 1)/rotationSlowDown;//*(rotation + 1 * rotationSpeed)/rotationSlowDown;
//rotation = rotation*Time.deltaTime*rotationSpeed;
angle=angle+1;
Debug.Log("angle");
Debug.Log(angle);
}
}
if (rotateJoystick.position.y<0)
{
if (angle>=maxDownAngle)
{
rotation = (Time.deltaTime*rotation - 1)/rotationSlowDown;
angle=angle-1;
Debug.Log("angle");
Debug.Log(angle);
}
}
//Debug.Log(rotation);
if (angle <= maxUpAngle angle >= maxDownAngle)
transform.Rotate (Vector3.right, rotation, Space.Self) ;
}