Sprites with different sizes

I have a spritesheet with sprites that are all different sizes (lets say idle is 40x20 and attack is 40x40) so whenever I animate it, it just moves around and looks really weird.

This is what the spritesheet looks like.


Is there any way to fix this?

Make sure the pivot point in the sprite editor “referes to the same point” for every sprite/frame (not necessarily in the center of the sprite, maybe on center of the shadow of your character for example). Also, check the boundary box for each sprite.