in 2D, I’m using a script to flip the sprite horizontally to show the player he is facing the other direction and not moonwalking, however this recently stopped working and I have no idea why. Are there any variables that would prevent a script which inverts the scale of an object from working? This is a snippet of the script I am using (your typical flip script)
if (h < 0 && facingRight)
{
FlipX();
print("Flip Left!");
}
if (h > 0 && !facingRight)
{
FlipX();
print("Flip Right!");
}
function FlipX(){
facingRight = !facingRight;
transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y);
}
well it kinda looks like you are making an loop with faceRight that will all ways = !faceright after the first time, you might want
Flipx(){
if (faceRight)
{
faceright=!faceright;
}
else
{
!faceright = faceright;
}
untested
other then that to little script, i would also try copying the script into a new one, just encase corruption.
This is my Mike’s version (c#)
void Flip ()
{
facingRight = !facingRight; // flipping to other direction
Vector3 theScale = transform.localScale; //get the local scale
theScale.x *= -1; // flip the x axis
transform.localScale = theScale; // apply back to local scale
}