trying to make this sprite face in the direction that it last faced

im trying to make this sprite face in the direction that it last faced after using the joystick:

if (Mathf.Abs(angle) > 90)
            {
                    facingRight = false;
                    Vector3 scale = transform.localScale;
                    scale.x = Mathf.Abs(scale.x);
                    transform.localScale = scale;
            }
            else if (Mathf.Abs(angle) < 90)
            {
                    facingRight = true;
                    Vector3 scale = transform.localScale;
                    scale.x = -1;
                    transform.localScale = scale;
              
            }
                if (facingRight)
                {
                    Vector3 scale = transform.localScale;
                    scale.x = -1;
                    transform.localScale = scale;
                }
                else if (!facingRight)
                {
                    Vector3 scale = transform.localScale;
                    scale.x = Mathf.Abs(scale.x);
                    transform.localScale = scale;
                }

All it does is snap back to facing the default direction when I stop using the joystick.

variable angle doesnt print any value when joystick isn’t being used (doesnt say angle is 0, possible it’s null)

Hi @weareallthereis

What are you actually trying to accomplish?

I wouldn’t like to start guessing, but if you are trying to typical 4-directional movement, you don’t have change your sprite unless there is some input.

the sprite faces right and left when i move the joystick around and i want it so it continues to face in the direction it last faced after i stop using the joystick.
ideal: >> use joystick >>, << let go of joystick <<
currently: >> use joystick >>, << let go of joystick >>

"the sprite faces right and left when i move the joystick around"

So are you saying you have some sort of circular movement control instead of press up key, move up kind of setup?

Edit: I’m asking this because you say “move joystick around” and you are using angle instead of vector2 for example…

It’s not blatantly apparent but I’m guessing that when you release the joystick, it resets to your default idle animation. Otherwise, it is resetting your image back to it’s default state.

You will need to go into your Joystick script to find this and fix it there. Now, if it’s animations then you will probably need to create an idle animation for each possible direction and set its state in the same place within the Joystick script. Now if you’re not using animations then you can probably remove the reset code upon joystick release and your player should remain facing that direction. Of course this is assuming you’re not changing states.