- Home /
Rotate camera only in 2 directions based on player touch
I want to rotate my camera based on player touch. If player moves his finger on horizontal direction then camera need to rotate on y -axis and player moves his finger on vertical direction then camera need to rotate on x-axis.
I have written this code but don't working as expected, it starts moving in any direction. Seems like can't under our control.
 // Update is called once per frame
     void LateUpdate ()
     {
     
         // If there are two touches on the device...
         if (Input.touchCount == 1) {
             // Store currnet touch.
             Touch touch = Input.GetTouch (0);
 
             Vector3 axis = touch.deltaPosition;
 
             transform.RotateAround (transform.position, axis, 4f);
         }
     }
pitch -= Input.GetTouch(0).deltaPosition.y rotSpeed Time.deltaTime; yaw += Input.GetTouch(0).deltaPosition.x rotSpeed Time.deltaTime;
         // limit for Y
         pitch = $$anonymous$$athf.Clamp(pitch, $$anonymous$$Y, maxY);
         this.transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
Answer by USMANHEART · Jan 04, 2017 at 10:11 AM
Simply just use Vector2 instead of Vector3
void LateUpdate () {
      // If there are two touches on the device...
      if (Input.touchCount == 1) {
          // Store currnet touch.
          Touch touch = Input.GetTouch (0);
 
          Vector2 axis = touch.deltaPosition;
 
          transform.RotateAround (transform.position, axis, 4f);
      }
  }
Your answer
 
 
             Follow this Question
Related Questions
player rotate to camera direction but not moving in it's direction 0 Answers
Need help for player rotation and camera rotation 0 Answers
How do i get the Raycast rotation? 1 Answer
Mouse axes based on position, not movement. 1 Answer
How to Reset Quaternion/Rotation On 3D Object After Dragging Mouse? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                