Gridwright Store

27 Nov 2026 · By Gridwright Studio

Flip a Sprite in Godot 4 Without It Jumping Sideways

Gridwright pack artwork for Flip a Sprite in Godot 4 Without It Jumping Sideways

You drew your character facing right, and in Godot 4 you turn on flip_h on the AnimatedSprite2D whenever the player walks left. It works, except that every turn makes the sprite hop a few pixels sideways while its collision box stays put. Or the hop is gone, but the sword's hitbox still swings on the right when the character faces left.

Both come from one fact: flip_h changes how the picture is drawn and nothing else. Every number below was measured on a test sprite rendered in Godot 4.7.2, and the script near the end was run there too.

Why flip_h moves your character

An AnimatedSprite2D draws each frame inside a rectangle the size of the frame. With Centered on, the default, the middle of that rectangle sits on the node's origin, and Offset moves the rectangle from there. flip_h mirrors the picture inside the rectangle. The rectangle itself doesn't move.

So the mirror line is the vertical middle of the frame. A body balanced on that line turns in place. A body that sits to one side lands on the other side, and it travels twice the gap.

Our test frame was 48 pixels wide with an 8-pixel body at columns 12 to 19, so the body's middle was 8 pixels left of the frame's middle. Facing right, the body spanned -12 to -4 from the origin. With flip_h on, it spanned 4 to 12: a 16-pixel hop on every turn, while a CollisionShape2D at the origin stays where it was.

Frames usually end up off-centre because a sword, a bow or a cape widens the drawing on one side, and whoever cut the sheet centred the whole drawing instead of the body.

What doesn't fix it

  • **Moving Offset.** Offset moves the rectangle, and the mirror line moves with it. With Offset x at 4, the body's middle was at -4 facing right and 12 facing left: the same 16-pixel hop.
  • **Turning Centered off.** The rectangle's corner goes to the origin, but the mirror line is still its middle. Our body went from 12-20 to 28-36 pixels: the same hop, and now the character stands to the right of its node.
  • **Flipping the CharacterBody2D with scale.x = -1.** move_and_slide writes the body's transform, and Godot reads scale and rotation back out of it: a mirror on x comes back as scale (1, -1) turned 180 degrees. The next scale.x = -1 turns that back to facing right, so in our test the body changed facing on every physics frame. Leave the body's scale at 1.

Fix 1: cut every frame around the feet

The clean fix is in the sheet. Pick the point the character stands on, usually the middle between its feet, and make every frame as wide on the left of that point as on the right. With the same body moved to columns 20 to 27 of the 48-pixel frame, it spanned -4 to 4 with flip_h off and on. No hop.

  • Find the feet column once, on the idle frame facing right, and use it for every animation, or the character slides when it starts walking.
  • Pad or crop each frame so that column sits in the middle. A weapon that sticks out on one side needs empty space on the other.
  • Keep Offset x at 0. With Centered on, set Offset y to half the frame height minus the y of the line under the feet: for a 32-pixel frame with feet on the bottom row, 16 - 32 = -16.
  • Toggle Flip H in the Inspector and watch the feet against the origin cross.

Packs drawn for engines do this for you. Our Side-View Characters use one 32x32 frame with the feet on the bottom rows and the same bottom-centre pivot in every frame, and ship facing right and facing left, so you don't need flip_h at all. Top-Down Characters ship left as its own row on every sheet too.

Fix 2: mirror the offset in code

When you can't re-cut the sheet, correct it in code. Measure how far the body's middle sits from the frame's middle in the right-facing art. Ours was 8 pixels to the left, so Offset x = 8 puts the body on the origin facing right. flip_h doesn't mirror Offset, so facing left you set -8 yourself. Measured that way, the body spanned -4 to 4 in both facings.

This is the script we ran, on a CharacterBody2D with an AnimatedSprite2D child and an empty Node2D child called Facing. It suits a character drawn facing right only, the usual setup in survivors-likes and many top-down games:

  • extends CharacterBody2D, with const SPEED := 80.0, an exported var art_offset_x := 0.0 (8 for our frame), var facing_left := false and @onready var sprite: AnimatedSprite2D = $AnimatedSprite2D.
  • In _physics_process: var input := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down"), then velocity = input * SPEED and move_and_slide().
  • if input.x != 0.0: facing_left = input.x < 0.0. Only sideways input changes the facing, so a character that stops or walks straight up keeps looking the way it last walked.
  • sprite.flip_h = facing_left, and sprite.offset.x = -art_offset_x if facing_left else art_offset_x.
  • $Facing.scale.x = -1.0 if facing_left else 1.0, for the children that turn with the sprite.
  • sprite.play("walk" if input != Vector2.ZERO else "idle").

In the test, walking left gave flip_h on, Offset x -8 and Facing at -1. Letting go kept all three and switched to idle. Walking down-right turned everything back at 80 pixels a second, the speed of a straight line.

Hitboxes and spawn points don't flip

flip_h only touches the drawing. An Area2D hitbox for the sword and a Marker2D where arrows spawn stay on the right while the character faces left. Put them under the Facing node and flip that instead of the body. Nothing writes a transform to it the way move_and_slide does, so its -1 stays.

In our test an 8x8 Area2D box placed 12 pixels right of a Facing node with scale.x = -1 was found 12 pixels to its left by a physics point query, and nothing was found on the right. Place every child as if the character faces right, and the pivot mirrors them all. The JSON of Side-View Characters gives the attack's hitbox and the spawn point for the arrow and the fireball, so those children can go where the art says.

Two more things that look like flip bugs

  • **Idle snaps back to one side.** A facing read from velocity is lost when velocity drops to zero. Change it only when there is input on that axis, as the script does.
  • **The up walk holds the sword in the wrong hand.** In a 4-direction game, if flip_h is still on from walking left when the player turns up, walk_up plays mirrored. Set flip_h from the facing: on for the facings that borrow a mirror image, off for every facing with its own drawing.
  • **Diagonals are faster.** Input.get_vector limits the length to 1, so the script's diagonal moved at 80. A vector from two Input.get_axis calls measured 1.414 on a diagonal, about 41% faster: call limit_length(1.0) on it first.

Let the Godot Animation Scene Builder do the measuring

Our Godot Animation Scene Builder does this from your sheet. Drop a sheet, a sheet per animation or loose frames, with the JSON from our packs, Aseprite or TexturePacker if there is one, and every animation is named by state and direction: idle_down, walk_left, run_up_right. It stands the sprite on its feet at the node's origin and makes its cell as wide on both sides of the feet, so flip_h mirrors it in place.

The Godot Animation Scene Builder's table of idle, walk, run, attack and block animations for each of 8 facings
What each facing plays, here for the 8-way knight from Isometric Characters: every facing has its own drawing.

Pick 8, 4 or 2 facings and a table shows what each one plays: its own animation, the mirrored side, or the nearest one where an animation is missing. Then walk the character around a test room on the page with WASD, Shift to run and J to attack.

A pixel art knight standing in the Godot Animation Scene Builder's test room
The test room: the knight's 64x64 frame with its feet at 32, 46, facing down-right.

The ZIP holds your art, a SpriteFrames .tres with every animation and its speed, a CharacterBody2D scene with the sprite on its feet and a collision box there, a typed movement script for 8, 4 or 2 facings with run and play_once() for attacks, and a test room to press F6 on. Nothing is uploaded.

For import settings that keep the pixels sharp, see how to import pixel art sprite sheets into Godot 4, and for how many facings to draw, 8 directions vs 4 directions for sprites.

What you make with the builder is yours for any game, commercial ones too. Our packs can go in commercial games but not be resold as files; see can I use game assets in a commercial game. If you need a character drawn in every facing, you can order a custom pack.

Found it useful? Share it

Get the art for your game

Our packs together in the $20 Megabundle, a custom pack drawn for your game, or the packs in this post from $9.99 each.

Best value

Gridwright Megabundle

Our packs and tools on itch.io in one bundle, for less than three of them one by one.

Get it for $20 (opens in a new tab)

Custom packs from $49

Not finding it? We draw it for your game, in 14 days or your money back.

Order a custom pack

Packs mentioned

Related guides