Restricting player camera rotation.x
Howdy,
Looking to add a simple restriction to an input script I'm working on that uses a dual joystick controller.
I need to restrict the amount of rotation that the camera can undergo. I've tried to work with clamping and manually checking the angles, but I haven't gotten anything to work yet. This script is attached to an empty gameobject containing the camera and a collider; needing to constrain rotation between -20 and 50 degrees..
 float ypos;
     float minheight;
     float maxheight;
 
 
     void Start () {
         ypos = transform.position.y;
         minheight = -20;
         maxheight = 50;
     }
     
     // Update is called once per frame
     void Update () {
 
         //2D X/Z movements 
 
         //X Axis
 
             var x = Input.GetAxis ("LeftHorizontal") * Time.deltaTime * 10.0f;
             transform.Translate (x * -1, 0, 0, Space.Self);
 
 
         //Z Axis
 
             var z = Input.GetAxis ("LeftVertical")* Time.deltaTime * 10.0f;
             transform.Translate (0, 0, z * -1, Space.Self);
 
 
 
         //X Axis Rotation (Vertical Rotation)
 
         var vertrot= Input.GetAxis ("RightVertical")* Time.deltaTime * 50.0f;
         transform.Rotate (vertrot, 0, 0, Space.Self);
 
 
         //Y Axis Rotation (Horizontal Rotation)
         var horizrot = Input.GetAxis ("RightHorizontal") * Time.deltaTime * 50.0f;
                 transform.Rotate (0, horizrot, 0, Space.World);
 
 
         //Constraint, forces player to remain at starting Y height position.
         if (transform.position.y != ypos)
             transform.Translate (0,(transform.position.y-ypos)*-1,0);
 
     }
Any ideas on how to constrain the movement process with this type of method?
Your answer
 
 
             Follow this Question
Related Questions
Problem with rotation on a player controller 0 Answers
Stopping 3rd person camera from looking too high or low? 1 Answer
Why does the FreezeRotation constraint still allow the rotation to be modified? 1 Answer
How to freeze all constraints on rigidbody except transform.forward? 0 Answers
Set Rotation 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                