Advertisement
AstralGames

Left/Right movement issue

Feb 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. if (Input.touchCount > 0)
  2.         {
  3.             Touch touch = Input.GetTouch(0);
  4.  
  5.             if(touch.phase == TouchPhase.Began)
  6.             {
  7.                 startTime = Time.time;
  8.                 startPos = touch.position;
  9.  
  10.             }
  11.             else if (touch.phase == TouchPhase.Ended)
  12.             {
  13.                 endTime = Time.time;
  14.                 endPos = touch.position;
  15.  
  16.                 swipeDistance = (endPos - startPos).magnitude;
  17.                 swipeTime = endTime - startTime;
  18.  
  19.                 if (swipeTime < maxTime && swipeDistance > minSwipeDist)
  20.                 {
  21.                     Swipe();
  22.                 }
  23.  
  24.             }
  25.         }
  26.        
  27.     }
  28.  
  29.     public void Swipe()
  30.     {
  31.         Vector2 distance = endPos - startPos;
  32.         if(Mathf.Abs(distance.x) > Mathf.Abs(distance.y))
  33.         {
  34.             Debug.Log("Horizontal Swipe");
  35.             if(distance.x > 0)
  36.             {
  37.                 Debug.Log("Right Swipe");
  38.                 CC.center = new Vector3(0, 1.28f, 0);
  39.                 CC.height = 2.52f;
  40.                 transform.Translate(Vector3.right * rightSpeed * Time.deltaTime);
  41.             }
  42.             if(distance.x < 0)
  43.             {
  44.                 Debug.Log("Left Swipe");
  45.                 CC.center = new Vector3(0, 1.28f, 0);
  46.                 CC.height = 2.52f;
  47.                 transform.Translate(Vector3.left * leftSpeed * Time.deltaTime);
  48.             }
  49.         }
  50.  
  51.  
  52.  
  53. PLAYER NOT MOVING SMOOTHLY INSTEAD HE "JUMPS TO THE RIGHT AND LEFT" CUTS FRAMES... OR SOMETHING... LIKE NO FLOAT.. "FRAME JUMPING"
  54. Anyone ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement