Question by 
               DimlyMad · May 23, 2018 at 02:55 PM · 
                androidiosmobiletouch controls  
              
 
              Move Character using Finger Gestures for Unity
Hi, I'm developing a mobile game and started using the free asset Finger Gestures Lite to interact with the character. So far I had no trouble setting up the swipe motion as the Attack gesture. However when I implement the movement using LongPress, the character runs at a very high speed, and I cannot control its direction. Can anyone help m, please?
Below is the code I have attached to the character.
     private void BeginDrag(float screenX){
 
         Vector3 pos = new Vector3 (screenX, 0.0f, 0.0f);
         pos = Camera.main.ScreenToWorldPoint (pos);
         RaycastHit2D hit = Physics2D.CircleCast (pos, 0.0f, Vector2.zero);
 
         if (hit.transform != null && hit.transform.gameObject.name =="Teolinda"){
 
             CharacterMain = hit.transform.gameObject;
             CharacterMain.GetComponent<Rigidbody> ().velocity = Vector3.zero;
 
             anim.SetBool ("IsWalking", true);
         }
 
     }
 
 
     private void DragTo (float screenX){
 
         if(CharacterMain == null){
             return;
         }
 
         Vector3 pos = new Vector3 (screenX,0.0f, 0.0f);
         pos = Camera.main.ScreenToWorldPoint (pos);
         CharacterMain.GetComponent<Rigidbody> ().MovePosition(pos);
         anim.SetBool ("IsWalking", true);
 
     }
 
     private void EndDrag (){
 
         anim.SetBool ("IsWalking",false);
     }
 
 
     private void LongPressGestureCallback(GestureRecognizer gesture){
 
         if (gesture.State == GestureRecognizerState.Began){
 
             BeginDrag(gesture.FocusX);
         }
         else if (gesture.State == GestureRecognizerState.Executing)
         {
             
             DragTo(gesture.FocusX);
         }
         else if (gesture.State == GestureRecognizerState.Ended)
         {
             
             EndDrag();
         }
 
     }
 
     private void CreateLongPressGesture(){
 
         longPressGesture = new LongPressGestureRecognizer ();
         longPressGesture.MaximumNumberOfTouchesToTrack = 1;
         longPressGesture.StateUpdated += LongPressGestureCallback;
         FingersScript.Instance.AddGesture (longPressGesture);
 
     }
 
              
               Comment
              
 
               
              Your answer