Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ARCore Rotation not working on swipe with one touch.Why?

Discussion in 'AR' started by zyonneo, Jun 14, 2019.

  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    From the below code the zoom is working with two fingers but my rotation is not working using single swipe.For testing i added a text.The text is getting updated with "One touch move" when I swipe the screen.
    Cannot understand the zoom is working but the rotation not working.Any help?

    Code (CSharp):
    1.  void FixedUpdate()
    2.      {
    3. //I Have increased to higher values no use
    4.         public float rotspeed=100f;
    5.  
    6.  
    7.         if (Input.touchCount > 0 && isLocked==true)
    8.           {
    9.               var touch = Input.GetTouch(0);
    10.              
    11.                 if ((Input.touchCount == 1 && Input.touchCount < 2 && Input.GetTouch(0).phase == TouchPhase.Moved) && !EventSystem.current.IsPointerOverGameObject(touch.fingerId) )
    12.                      {
    13.                 // Get movement of the finger since last frame
    14.  
    15.                          Debug.Log("One touch Move");
    16.                          Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    17.                 Messagetxt.text = "One touch Move";
    18.  
    19.            
    20.               this.transform.Rotate(Vector3.up, -touchDeltaPosition.x * rotspeed * Time.deltaTime, Space.World);
    21.            
    22.  
    23.  
    24.                      }
    25.  
    26.  
    27.  
    28.             if (Input.touchCount == 2 &&  !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
    29.                      {
    30.  
    31.  
    32.  
    33.  
    34.  
    35.                         // Store both touches.
    36.                         Touch touchZero = Input.GetTouch(0);
    37.                         Touch touchOne = Input.GetTouch(1);
    38.  
    39.                         // Find the position in the previous frame of each touch.
    40.                         Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
    41.                         Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
    42.  
    43.                         // Find the magnitude of the vector (the distance) between the touches in each frame.
    44.                         float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
    45.                         float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
    46.  
    47.                         // Find the difference in the distances between each frame.
    48.                         float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
    49.  
    50.  
    51.                         float scale = deltaMagnitudeDiff * perspectiveZoomSpeed * Time.deltaTime;
    52.  
    53.  
    54.                         Vector3 tt;
    55.                         tt.x = scale;
    56.                         tt.y = scale;
    57.                         tt.z = scale;
    58.                 if (this.transform.localScale.x > 0 && this.transform.localScale.y > 0 && this.transform.localScale.z > 0)
    59.                         {
    60.                     this.transform.localScale += new Vector3(-scale, -scale, -scale);
    61.  
    62.                         }
    63.  
    64.                 if (this.transform.localScale.x < 1 && this.transform.localScale.y < 1 && this.transform.localScale.z < 1)
    65.                         {
    66.                     this.transform.localScale += new Vector3(scale, scale, scale);
    67.  
    68.                         }
    69.  
    70.                 if (this.transform.localScale.x > 3 && this.transform.localScale.y > 3 && this.transform.localScale.z > 3)
    71.                         {
    72.                     this.transform.localScale += new Vector3(scale, scale, scale);
    73.  
    74.                         }
    75.  
    76.  
    77.  
    78.                 }
    79.  
    80.            
    81.  
    82.    
    83.                
    84.            }
    85.  
    86.  
    87.      }
     
  2. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    I am using the later ARcore sdk with HelloARcontroller for placing the object on real world