Frame Animation; Positioning Issue.. please help.!

Hey.! I use frame animation importing from photoshop.
I started on my swing animation and i noticed a small issue; when i animation plays the sprite itself seems to get bigger and pushes the player out of its position, im guessing because the swing animation is larger then the default. Any ideas to fix this.?

TLDR; The animation forces the sprite to move backwards everytime the attack animation plays, as you can see the colliders are out of position too.

Screenshot 2024-05-09 100638

I’m just speculating here, but the problem may be related to the sprite pivot point and the size of the individual sprites.

By default, when you import an image into Unity it sets the pivot point to “Center”. This means that the Sprite Renderer will draw the image such that the center of the image is placed at the transform.position location.

If your idle image and attacking image have different widths, then the part of the image that contains the character will be rendered further to the left so that the entire image can be centered at the target position.

There are a few ways to address this, but they all boil down to the same rule: The position of the pivot relative to the “character” in all of the images needs to be consistent.

The way I have addressed this issue is to make sure my character is always centered in the images that I import into Unity. This may add some empty space on one side of the image, but it saves me a lot of headache.