flipping 3D rigidbody

hello everyone, im making a 2.5D game where the player moves right and left only and hes a 3D object (rigidbody3D)…

i have this ode implemented for movement:

        _HorizontalAxis = Input.GetAxis("Horizontal");

        //Takes Only Direction of movement
        Vector3 _moveHorizontal = transform.right * _HorizontalAxis;
        Debug.Log(_HorizontalAxis);

        // Final Movement Vector (Multiply Direction with Speed)
        Vector3 _velocity = (_moveHorizontal).normalized * movementSpeed;

        motor.Move(_velocity);

        // Flipping the Player Left and Right
        if (_HorizontalAxis > 0 && !facingRight)
        {
            //flip the player.
            motor.fFlip();
        }

        // Otherwise if the input is moving the player left and the player is facing right...
        else if (_HorizontalAxis < 0 && facingRight)
        {
            //flip the player.
            motor.fFlip();
        }

will the thing is when i move right OR left the object just moves right all the time …
i know im missing something somewhere it’s just my brain is teased >,<

this is my Fliping function:

    public void fFlip()
    {
        // Flip the character
        if (!playerController.facingRight)
            transform.eulerAngles = new Vector3(0, 0, 0);
        else
            transform.eulerAngles = new Vector3(0, 180, 0);

        // Switch the way the player is labelled as facing.
        playerController.facingRight = !playerController.facingRight;
    }

I really appreciate your help and heads up for me to see the missing part >,>

Thanks,
HeroO

Use world axes instead of local axis transform.right.

Vector3 _moveHorizontal = transform.right * _HorizontalAxis;

When you rotate the character in the fFlip( ) function by setting the eulerAngles transform.right is being faced left as well. That makes the player either move positive along the right axis when pressing the right key OR negative along the negative transform.right (which is the local left axis).

Two possible solutions:

  1. Use the equivalent world axis to transform.right when character is facing right:

    Vector3 _moveHorizontal = Vector3.[equivalentWorldAxis] * _HorizontalAxis;

  2. Getting the Math.Abs( ) value of _moveHorizontal when calculating the _velocity.

    Vector3 _velocity = Mathf.Abs(( _moveHorizontal).normalized )* movementSpeed;

Your character moves either positive along the local right axis or negative along the local right axis looking in the opposite direction.

Vector3 _moveHorizontal = transform.right * _HorizontalAxis;

To fix this you could use an equivalent fixed global axis to transform.right when the character actually is facing right:

Vector3 _moveHorizontal = Vector3.[equivalentWorldAxis] * _HorizontalAxis;

Or you fix the issue when calculating the _velocity:

Vector3 _velocity = Mathf.Abs(( _moveHorizontal).normalized ) * movementSpeed;