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!