- Home /
2D game unity player flip problems
Hey, I have a question, I hope u can help me I want to change the players X Scale then my player turns around weird... see image X = 0.5 : http://prntscr.com/nx875f X = -0.5 http://prntscr.com/nx87a1
My flipping Code is :
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
private void Flip() { facingRight = !facingRight; Vector3 Scaler = transform.localScale; Scaler.x *= -1; transform.localScale = Scaler; }
thank you for helping me
Answer by Magso · Jun 04, 2019 at 01:26 PM
Position your sprite so the image is central to the parent. The pivot point of the sprite is at the corner and if that is positioned to the parent's origin it will cause the offset of the character.
Hey $$anonymous$$agso,
Thank you so much for your answer but I dont really know which sprite you mean and what a pivot point is. Could you please tell me in a few steps on what for a layer I should press and change?
Dear Connor
And I try to position the image central to the parent but it does not work :(
Basically,
+ < the parent you're changing the scale on is here.
[] < Your character is here.
so at scale x -1 it flips like this,
+ < parent
[] < character
You need it so the character is central
+
[] < like this
Hey $$anonymous$$agso, thank you for your answer but could you tell me what for a value I have to change to let the player be centered? Because I look for that but cant find it! :(