I want to create a small Android game, where i am flying a plane, now the thing is i wanna limit the rotation of the plane , so that it wont go lesser than -45 and greater than 45 degree in Z axis , means when ever i take joystick to right then the plane should rotate in Zaxis and stay at 45 degree and not cross 45 degree
so directly i mean to limit the Zaxis rotation of plane between -45 and 45 degree
i am using this piece of code , which is giving me pretty fair results and the gameObject is limited at 45 degree but i am having a issue that whenever the gameobject reaches at 0 the Rotation of GameObject bounces back to max Limit provided ie, maxRotation
float hortemp = CrossPlatformInputManager.GetAxis("Horizontal");
float TAngle = Mathf.Clamp(hortemp, -5, 5);
transform.Rotate(0, 0, -TAngle);
float minRotation = -45f;
float maxRotation = 45f;
Vector3 currentRotation = transform.localRotation.eulerAngles;
currentRotation.z = Mathf.Clamp(currentRotation.z, minRotation, maxRotation);
transform.localRotation = Quaternion.Euler(currentRotation);
please help me with this, how do i fix this