help rotating and moving for mobile
i move with joystick on left side of the screen using IDragHandler, IPointerUpHandle functions and rotate on the right side of the screen using input.touches. The rotation and movement work okay but if the touch is stationary the player starts jittering around or if i try rotate too quickly the player jitters around. Im storing the rotation touch in a list and using it (hoping atleast thats whats going on), any help please?
Answer by mikeywill21 · Mar 28, 2020 at 02:54 AM
It's the standard joystick that provides input based on direction but this is my input touch script, I am trying to preform an orbiting rotation:
Public class TouchLocation { Public int touchID; Public TouchLocation(int _NewTouchID){ touchID = _NewTouchID; } }
List TouchStorage = new List; Private float rotationPitch = 0.0f; Private float rotationYaw = 0.0f; Private Touch RightTouch; Private Vector2 LastTouchPosition Image RotationImage_Image
Void Update() { PlayerRotation(); }
Void PlayerRotation() { If(Input.touchCount > 0) { for(int I = 0; I < Input.touchCount; I++) { If(RectTransformUtility.RectangleContainsScreenPoint( RotationImage_Image.rectTransform, Input.GetTouch(I).position, null) { Touch CurrentTouch = Input.GetTouch(I); If(CurrentTouch.phase == Touch phase.Began) { TouchStorage.Add(new TouchLocation(CurrentTouch.fingerId); LastTouchPosition = CurrentTouchPosition; } else if ( CurrentTouch.phase == Touch phase.Moved) { TouchLocation ThisTouch = TouchStorage.Find(TouchLocation => TouchLocation.touchId == CurrentTouch.fingerId); Vector3 Offset = Input.GetTouch(ThisTouch.touchId).deltaposition - LastTouchPosition; LastTouchPosition = Input.GetTouch(ThisTouch.touchId).position; RotatePlayer(Offset.x, Offset.y, ExternalControl.Sensitivity.x); } else if (CurrentTouch.phase == TouchPhase.Stationary) { LastTouchPosition = CurrentTouch.position; } else if(CurrentTouch.phase == TouchPhase.Ended) { TouchLocation ThisTouch= TouchStorage.Find(TouchLocation => TouchLocation.touchID == CurrentTouch.fingerId); TouchStorage.RemoveAt(TouchStorage.IndexOf(ThisTouch); LastTouchPosition = new Vector2(); } } } } }
Void RotatePlayer(float xaxis, float yaxis, float rotationSpeed) { Float rotX = xaxis rotationSpeed Mathf.Deg2Rad; Float rotY = yaxis rotationSpeed Mathf.Deg2Rad; Transform.Rotate(Vector3.up, rots); }
Excuse anny misspelling I wrote this answer from my phone :(.
Your answer
Follow this Question
Related Questions
play a sound like in a piano when touching a collider2D 1 Answer
Why my input both mouse and touch can't detected? 0 Answers
TouchPhase.Began hold problem 0 Answers
input issues 0 Answers