Flip Sprite Wall jitter flipping

Each time the player touched a wall and the same direction key is pressed, the physics/game engine re-aligns the collider overlap by moving the collider from the collision point in the opposite direction, which flips the myRigidbody.velocity.x directional speed, which in turn flips the sprite direction, which is set by the Math.Sigh… function. To get around this, the player flip sprite was change to:

void FlipSprite()
{
if (isAlive) return;
float switchDir = myRigidbody2D.velocity;
if (switchDir > 0.1f && swirchDir <= 0.1f) return;
if (switchDir <= 0.1f) transform.localScale.x = new Vector2(-1f, 1f);
if (switchDir >= 0.1f) transform.localScale.x = new Vector2(1f, 1f);
}

Hope this help others with wall jitters :slight_smile:

Privacy & Terms