- Home /
Help Wanted. Switching localscale starts unwanted animation state.
If my player is sliding down the wall, you can see that whenever I stop sliding so i start the fall animation, for a second it starts the run animation. Slide and Run animation states are not connected, and the problem goes away if I disable the SwitchDirections() function. I really haven't found a way to fix this. Was sitting the whole day trying to change my animation changes, but it occurs the problem was in that script. Why is it happening?
private void Update()
{
SwitchDirection();
CheckMovement();
}
private void FixedUpdate()
{
}
private void SwitchDirection()
{
if (_moveInput > 0)
{
FlipAnimation(false);
}
else if (_moveInput < 0)
{
FlipAnimation(true);
}
}
private void FlipAnimation(bool isFlipped)
{
if (isFlipped)
{
gameObject.transform.localScale = new Vector3(-1, 1, 1);
_isFacingRight = false;
}
else
{
gameObject.transform.localScale = Vector3.one;
_isFacingRight = true;
}
}
_moveInput is just Input.GetAxis("Horizontal"); _isFacingRight is by default true because the object at start is facing right. Watch the video for better understanding.
Your answer
Follow this Question
Related Questions
Sprite animation 2 Answers
SpriteManager 2 1 Answer
Move Transform to Match 2d Animation 0 Answers
Rolling Barrels through Platforms 0 Answers