Flipping sprite resets on no input

Hi there,

I’m trying to implement a a very basic sprite controller I can use across multiple objects. It’s mostly turning out okay except for flipping the sprite based on input. The relevant code is:

        if (Input.GetAxis("Horizontal") !=0) //originally if (moveAmount.x !=0), both have issues re: sprite flipping when this is false
        {
            float flipSprite = Input.GetAxisRaw("Horizontal"); //issue: sprite flips uncontrollably when touching the bottom of a slope using moveAmount
            if (flipSprite > 0)
            {
                spriteRenderer.flipX = false;
            }
            else
            {
                spriteRenderer.flipX = true;
            }
            HorizontalCollisions(ref moveAmount);

        }

This gets called in an update method and mostly works as intended, but there is an issue where if after the first time I release the arrow keys, the renderer flips the sprite. I don’t modify the x scale of the object anywhere else. The way I understand it is that when I release the input, the axis resets to 0 and the code inside the brackets shouldn’t get called. I’m not sure what I’m doing wrong here. If anybody could give me some suggestions or alternatives I’d greatly appreciate it.

Thanks!

I managed to fix it, the solution was to use Input.GetAxisRaw in the first if statement! I hope this helps anybody else who has the same issue as mine or wants to use this code to implement sprite flipping.