I made the control of the character on the keyboard and on the keyboard. On the touch screen, sometimes, at regular tapes, the character’s speed dramatically (about 2 times) increases. The next tap successfully turns everything off. Absolutely by chance, I tried to tap and hold 2 times in a row - I could not reproduce it.

public Vector2 rightForce = new Vector2(300, 0); public Vector2 leftForce = new Vector2(-300, 0); void Update() { if (Input.touchCount > 0)//код для тачскрина { var touch = Input.GetTouch(0); if (touch.position.x < Screen.width / 2) { GetComponent<Rigidbody2D>().velocity = Vector2.zero; GetComponent<Rigidbody2D>().AddForce(leftForce); } else if (touch.position.x > Screen.width / 2) { GetComponent<Rigidbody2D>().velocity = Vector2.zero; GetComponent<Rigidbody2D>().AddForce(rightForce); } } } if (Input.GetKeyUp(KeyCode.LeftArrow)) //код для клавиатуры. { GetComponent<Rigidbody2D>().velocity = Vector2.zero; GetComponent<Rigidbody2D>().AddForce(leftForce); } if (Input.GetKeyUp(KeyCode.RightArrow)) { GetComponent<Rigidbody2D>().velocity = Vector2.zero; GetComponent<Rigidbody2D>().AddForce(rightForce); } } 

    1 answer 1

    Problem solved. I changed Update to FixedUpdate and it all worked.