- Home /
 
Android Unable to track finger touch after orientation change
Hi People,
I have two objects on screen with colliders which I shoot using raycast to trigger some events. which does pretty good until I rotate the phone... The problem here is that Input.mousePosition and Input.getTouch(0).position both return (infinity, - infinity, 0) after the orientation change. So no matter where people touch after the orientation change all I get is a vector with infinity for x and -infinity for y. Which cannot be used to make a ray casting from the camera.
Is there something I can do to reset the Input so that it adapt to the new screen width and height and become able to track finger position again?
     if(Input.GetMouseButton(0)){
         print (Input.mousePosition);
         Ray ray = camera.ScreenPointToRay(Input.mousePosition); //here
         Debug.DrawRay(ray.origin, ray.direction *10, Color.cyan);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit)){
             print (hit.collider.gameObject.name);
             if(hit.collider.name.Equals ("rope_leveler(Clone)")){
                 pullLeveler();
             }
             else{
                 pullClearRope();
             }
         }
     }
     foreach (Touch touch in Input.touches) {
         if (touch.phase == TouchPhase.Began) {
             // Construct a ray from the current touch coordinates
             print ("touched : "+touch.position.ToString());
             Ray ray = Camera.main.ScreenPointToRay (touch.position); //here
             Debug.DrawRay(ray.origin, ray.direction *10, Color.cyan);
             
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit)){
                 // Create a particle if hit
                 print (hit.collider.gameObject.name);
                 if(hit.collider.name.Equals ("rope_leveler(Clone)")){
                     pullLeveler();
                 }
                 else{
                     pullClearRope();
                 }
             }
         }
     }
 
              Your answer
 
             Follow this Question
Related Questions
raycasting and layermask question 2 Answers
Detect touch lifted from object regardless of lift location 0 Answers
i need help in walking character in android, using raycast where user touches? 0 Answers
Android touch 3d Object event 1 Answer
How do you Draw a Line Using your Finger's Position on Android 3 Answers