Changing local scale changes player position

Hi everyone!

I have problem with flipping my character, flip is working fine but it changes player position all the time. I’m gonna show you in pics what this does look like.
This is default stance:

this is after pressing left arrow key:

If I press right arrow key he will go back to his default stance. Also I observed that when I switch the x all of transform positions stays the same. Any help?

Code I use for moving a player and to flip him:

void Update()
    {
        movex = Input.GetAxis("Horizontal");
        anim.SetFloat("Speed", Mathf.Abs(movex));
        rb.velocity = new Vector2(movex * SpeedPlayer, 0f);
        if (movex > 0 && !facingRight)
        {
            Flip();
        }
        else if (movex < 0 && facingRight)
        {
            Flip();
        }
    }
    void Flip()
    {
        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }

To flip a character by multiplying its scale by -1:
The Sprite of your character has to be at the exact center of your gameObject.
Also, the “drawing” of your character (the human), has to be at the exact center of your Sprite.
Your project certainly has one or both of these issues.

1 Like

I’ve created a whole new gameObject, centered it on my character and now its working, thank you :slight_smile:

Glad you found a solution