- Home /
 
 
               Question by 
               KimikoChujo · Aug 05, 2014 at 10:53 PM · 
                camerarotatecamera rotatecamera rotation  
              
 
              Rotate a camera with mouse drag
I try making 3D modelvewer.
This script is work. but I also use Automatically Rotate. Camera to rotate when I press the x. But when the camera has stopped rotating, back the start rotation.
What I want to do is the following two. [Press x : Rotate Automatically] [Click and drag : Rotate] When the camera stop the rotation, the angle of the camera is like to be unchanged.
 var target : Transform;
 
 var xSpeed = 250.0; var ySpeed =
 120.0; var movSpeed = 250.0;
 
 var yMinLimit = -20; var yMaxLimit = 80;
 
 var zoomSpeed = 250; var zoomMin = 1; var zoomMax = 80;
 
 private var x = 0.0; private var y =
 0.0;
 
 private var distance :float; private var movX : float; private var movY : float;
 
 
 function Start () {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
 
 }
 
 function LateUpdate () {
     
     
 
     if (Input.GetMouseButton(2) || Input.GetAxis("Mouse ScrollWheel") ) {
         distance += (Input.GetAxis("Mouse Y") + Input.GetAxis("Mouse ScrollWheel") * 10 ) * zoomSpeed *
 0.02;
         if (distance < zoomMin) distance = zoomMin;
         if (distance > zoomMax) distance = zoomMax;
     }
 
 
      }
          
  
     if (target && Input.GetMouseButton(0)) {
         x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
                    y = ClampAngle(y, yMinLimit, yMaxLimit);      }
                 
     var rotation = Quaternion.Euler(y, x, 0);
         
     transform.rotation = rotation;
     transform.position = position;
     target.LookAt(this.transform); }
 
 
 static function ClampAngle (angle : float, min : float, max : float) {     if (angle < -360)         angle += 360;     if (angle > 360)         angle -= 360;     return Mathf.Clamp (angle, min, max); }
 
              
               Comment
              
 
               
              Your answer