flip X or - scale.x

Hi i want to know what is the best pratice.
I want to flip a sprite who is a child and i dont know if i should scale the parent X to +/- value or to work on the child transform on flip it with the flipX ?
I make try and the box collider are flipping right maybe later i will have some error like negative value.
But i struggle to find a good answer on the 10 first google suggestion.
Thx for the repply

This is what i did a long time ago and i have just kept it this way.

private void Flip()
//    {
//        //Switch the way the player is labelled as facing.
//        facingRight = !facingRight;

//        //Multiply the player's x local scale by -1.
//        Vector3 theScale = playerGraphics.localScale;
//        theScale.x *= -1;
//        playerGraphics.localScale = theScale;
//    }

The Box Collider is on the Parent gameobject and this flip script works on the Graphics child object so it doesnt mess up the Box Collider. Now, if the box collider is perfectly center then it shouldnt matter as it will still be aligned.

I pretty much never use the SpriteRenderer’s flip options and always just set the scale to a +/- value.
Reason being, if your GameObject has any child sprites/other objects that need to align a certain way with the direction of the flipped sprite, then changing the scale will keep the children aligned, while using the SpriteRenderer flip-options will not.

For example, imagine you have some kind of animal GameObject with a few different SpriteRenderers for each body-part:
6747439--777943--upload_2021-1-20_23-13-7.png
If you wanted to flip the animal to face the opposite direction, setting “flip X” on all the SpriteRenderers would just result in this:
6747439--777946--upload_2021-1-20_23-13-13.png
Whereas inverting the scale of the parent GameObject would result in what you’d expect:
6747439--777949--upload_2021-1-20_23-13-50.png

2 Likes

Ok thx for the reply.
I found wanted to use the same solution cuz i have a shoot spwaner who need to flip as well and this one is not centered like the box collider. And i suppose the animator will run fine too. I need to make some test about this one last question.
Thx for the reply.
Good dev and stay safe