Question by
AndhireCo · Jan 29, 2019 at 11:11 PM ·
animation2dplatformer
changing to animation idle when i change too fast the moving directions?
I am new working in 2D games. And i am making the animation run. When my character is running and i change the directions fast. A little moment it changes to idle animation. And i know how to fix it. Here you can see it better: https://gph.is/2RrBaYu Thanks a lot!!!
void movePlayer()
{
Vector2 v = new Vector2(0, rb.velocity.y);
if (Input.GetAxisRaw("Horizontal") > 0.1f)
{
v.x = movementSpeed * Time.deltaTime ;
}else if (Input.GetAxisRaw("Horizontal") < -0.1f)
{
v.x = -movementSpeed * Time.deltaTime;
}
if(v.x > 0)
{
spr.flipX = false;
}
else if(v.x < 0)
{
spr.flipX = true;
}
rb.velocity = v;
animator.SetFloat("Run", Mathf.Abs(Input.GetAxisRaw("Horizontal")));
}
Comment
Answer by xxmariofer · Jan 29, 2019 at 11:26 PM
Hello, thats cause you axis value is 1 when going right and -1 when going left, and when interpolating movement it might be 0. You should not be changing the animator with the axis but with the velocity change the line to this:
animator.SetFloat("Run", Mathf.Abs(v.x));
Your answer
![](https://koobas.hobune.stream/wayback/20220612190734im_/https://answers.unity.com/themes/thub/images/avi.jpg)