How do I flip my 2d pixel character left and right with a different animation?,how do I flip my 2d pixel character left and right in a non weird manner?

So I’ve got my player to flip on not a weird manner but when I added the gun sprite animation when the player flips in creates a gap kinda thing I don’t know how to fix it I’m still kinda new at this programming thing,See I already have made it so the player can it can flip in not a weird way but when I added a gun sprite animation
It started to flip in a weird manner what should I do

2 Answers

2

You should try just rotating whole player ( parent witch children ) 180 degrees on Y axis. Make sure gun is a children of player and whenever you want to flip, propably checking Input in Update then do:

void Update(){
  if(Input.GetKeyDown(KeyCode.A) { // we flip
       transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z);
    }else if(Input.GetKeyDown(KeyCode.D)) { // we back to normal going right
      transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z);
   }
}

See that wouldn’t work because it’s a 2d pixel game for the idle and walking animation I made it so it rotates by changing the local scale but the problem is the animation when made the sprites for the gun it doesn’t properly flip Yours would work in a 2d game though

Yo sorry this is super late, I thought id help others out but there’s actually a really simple way

    private SpriteRenderer sprite;

void Start()
{
        sprite = GetComponent<SpriteRenderer>();
}

void Update()
{
        if (Input.GetKey(KeyCode.A))
          {
                        sprite.flipX = true;
           }

        if (Input.GetKey(KeyCode.D))
           {
                              sprite.flipX = false; 
           }
}