What am I doing wrong in my if statement?

Goal: to flip the 2D character sprite/animation based on aiming and moving.

Immediate goal: to have the animation set to “dodge right” even if (Aim Horizontal < 0)

Problem: for some reason if ( Aim Horizontal < 0 && Move Horizontal < 0 && isDodging) the animation is still playing the dodge animation as dodging right

Current code:

           //Flipping animation direction
            if (usingController)
            {
                if (player.GetAxis("Aim Horizontal") < 0)
                {
                    if (!isDodging)
                    {
                        transform.localScale = new Vector3(-1f, 1f, 1f);
                        gunArm.localScale = new Vector3(-1f, -1f, 1f);
                    }

                    else
                    {
                        if (player.GetAxis("Move Horizontal") < 0)
                        {
                            transform.localScale = new Vector3(-1f, 1f, 1f);
                            gunArm.localScale = new Vector3(-1f, -1f, 1f);
                        }

                        else
                        {
                            transform.localScale = Vector3.one;
                            gunArm.localScale = Vector3.one;
                        }
                    }


                }

                if (player.GetAxis("Aim Horizontal") > 0)
                {
                    transform.localScale = Vector3.one;
                    gunArm.localScale = Vector3.one;

                }

                Vector2 shootingDirection = crosshairCont.transform.localPosition;
                shootingDirection.Normalize();
                angle = Mathf.Atan2(shootingDirection.y, shootingDirection.x) * Mathf.Rad2Deg;
            }

Maybe my logic is off. What am I doing wrong here?

Maybe, who knows. Definitely bust out and liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

Get rid of inline checks of Input.GetAxis() and instead put them into temporary variables so it is easy to reason about them and print them as a complete “this is the current state right now” line of information.

Or attach the debugger, see what code is running… but that’s harder with an interactive game because it freezes when the breakpoint trips.

Have debugged the crap out of it. Despite Horizontal Aim & Horizontal Move both reading < 0, the new Vector is showing up as Vector3(1f, 1f, 1f).

Leads me to believe I’ve made it a double negative somehow, but based on the logic above I’m just not sure how.