Dashing left

Hello all I am working on a 2D platformer and I have a dash mechanic implemented I can dash to the right just fine it works perfectly. But when I am facing left and use my dash the dash still makes me dash right. Is there something I am missing my debug log that says I am dashing left doesn’t even play. I have been stuck on this issue for a while. Looking forward to some insight. Here is my code
void Dash()
{

        lastDash += Time.deltaTime;

        if (lastDash >= dashCD && onGround == true && Input.GetKeyDown(KeyCode.F))
        {
            lastDash = 0f;
            float dashDirection = Input.GetAxis("Horizontal");
            float dashSpeed = 500;
            GetComponent<Rigidbody2D>().velocity = new Vector2(thePlayer.MaxDashSpeed() * dashDirection, GetComponent<Rigidbody2D>().velocity.y);
            Debug.Log("I am dashing!");
            Debug.Log("DashTime = " + thePlayer.DashTimer());
            Debug.Log(isDashing);
            rb.AddForce(transform.right * dashSpeed);

            
        }

        if (lastDash >= dashCD && onGround == true && Input.GetKeyDown(KeyCode.F) && facingRight == false)
        {
            lastDash = 0f;
            float dashDirection = Input.GetAxis("Horizontal");
            float dashSpeed = 500;
            GetComponent<Rigidbody2D>().velocity = new Vector2(thePlayer.MaxDashSpeed() * dashDirection, GetComponent<Rigidbody2D>().velocity.y);
            Debug.Log("I am dashing left!");
            Debug.Log("DashTime = " + thePlayer.DashTimer());
            Debug.Log(isDashing);
            rb.AddForce(transform.right * -1);

        }




    }

Kindly,

Harpoaian

You might want to dash in the direction you are facing (transform.forward) rather than the direction the controls are being held in at that moment. Ask yourself “what if they aren’t pushing left OR right?”.

You could also remember to only use ‘1’ or ‘-1’ for your direction, since it should probably give you the same burst of speed no matter how much the user is pushing the control.

I figured it out guys here is the final code. I can’t believe the solution was so simple! My player character runs on a state machine and I have a player data model script. So I set up the dashSpeed variable in the data model script and then I intialized the player data model and my rigidbody2D script in my Start(); thePlayer = player.GetComponent(); rb = GetComponent();
Then in the dash script I call the velocity class of rigidbody and set it = to Vector2.left and then I multiply the vector by the dashSpeed variable in my player data model script and TADA! I can dash left. This also works for my right dash as well. I did discover that it doesn’t work as efficiently as my old dash but I just need to make some tweeks to it.
This also works for my Air Dash I just had to create a different speed variable for air and idle dash in my player data model script. I will need to make a dash function for when my player is in the idle state as well. The reason I have to do all this is because the speed dash compared to when I am moving to when I am idle are totally different.

  void Dash()
    {
        
        lastDash += Time.deltaTime;

        if (lastDash >= dashCD && onGround == true && Input.GetKeyDown(KeyCode.F))
        {
            lastDash = 0f;
           
            rb.velocity = Vector2.right * thePlayer.DashSpeed();
            
          
            if (facingRight == false)
            {
                lastDash = 0f;

                Debug.Log("DashTime = " + thePlayer.DashTimer());
                Debug.Log(isDashing);
                
                rb.velocity = Vector2.left * thePlayer.DashSpeed();

            }
            
            
        }
       




    }

Kindly,

Harpoaian