Quickly changing directions on 2d character with forces

Howdy,

I have this character that everytime he hits the ground he jumps and also moves sideways while in mid-air.

The problem is, since i’m using forces to drive him to the left or right, it takes a bit of time for him to accelerate to the opposing direction. I need some ideas on how to improve air-control so i can make it react quicker to direction changes whilst in the air.

The only idea i have so far is to somehow detect the direction change and apply a tiny force to help the character change direction faster. Unfortunately i’m a newbie at unity and game development in general so i don’t really know how to accomplish such thing and having touch controls doesn’t help either since most code samples on the web use keyboard/mouse input.

Any reading material, code sample or overall help is deeply appreciated.

Here is my character controller script ( the parts that matter ):

void FixedUpdate(){
       
        if (Input.touchCount > 0) {
            Touch touch = Input.GetTouch(0);

           // handle player movement sideways
            if( touch.position.x < Screen.width/2 ) {
                moveLeft();
            } else if( touch.position.x > Screen.width/2 ) {
                moveRight();
            }

            if(rigidbody2D.velocity.magnitude > maxSpeed){
                rigidbody2D.velocity = rigidbody2D.velocity.normalized * maxSpeed;
            }
        }
    }

    void moveLeft(){
        rigidbody2D.AddForce(-Vector2.right * 7 );
    }

    void moveRight(){
        rigidbody2D.AddForce(Vector2.right * 7);

    }

I think this could be resolved by zeroing the horizontal velocity like this:

  • if( touch.position.x < Screen.width/2 ) {

  • rigidbody2D.velocity.x = 0;

  • moveLeft();

  • } else if( touch.position.x > Screen.width/2 ) {

  • rigidbody2D.velocity.x = 0;

  • moveRight();

  • }