- Home /
 
               Question by 
               unity_bR9Y9NLBHGoe0w · Sep 15, 2018 at 01:59 PM · 
                mouseanglemouse orbit  
              
 
              Make an Orbit camera with Z rotation,Mouse Orbit with Z rotation
Hello everybody
i would like to implement a mouse orbit like the one in the wiki http://wiki.unity3d.com/index.php/MouseOrbitImproved except that i would like to be able to rotate aloung to z axis of the camera and to keep the same behaviour
 public Transform target;
 public float distance = 5.0f;
 public float xSpeed = 120.0f;
 public float ySpeed = 120.0f;
 float x = 0.0f;
 float y = 0.0f;
 
 void LateUpdate()
 {
     if (target)
     {
         if (Input.GetMouseButton(0))
         {
             x = Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
             y = Input.GetAxis("Mouse Y") * ySpeed * distance * 0.02f;
             Quaternion rotation = Quaternion.Euler(transform.rotation.eulerAngles+transform.right * y  + transform.up * x);
             distance = distance - Input.GetAxis("Mouse ScrollWheel") * 5;
          
             Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
             Vector3 position = rotation * negDistance + target.position;
             transform.rotation = rotation;
             transform.position = position;
         }else if (Input.GetMouseButton(1))
         {
             transform.Rotate(Vector3.forward * Time.deltaTime * 100);
         }
     }
 }
but i cant make it work
Any help / tips are welcome ! ;)
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                