Godot Top Down Animation: 8 Direction Movement
Make a Godot 4 top down character walk and face 8 directions: CharacterBody2D movement, animations named by direction, mirrored sides, a one-shot attack.

You have a character sheet with a walk for every direction and a CharacterBody2D that slides around. Joining the two is where many top-down games stall. The character is faster on diagonals. It snaps back to face down every time you let go of the keys. The left walk is the right one flipped, and the character hops sideways each time it turns. You press attack and idle wipes it out a frame later.
Each has a known cause and a short fix. Below is a whole Godot 4 movement script that walks, faces 8 directions and attacks once, run line by line in Godot 4.7.2 with the numbers we measured, then the three faults a short script leaves in.
1. The nodes
A top-down character is three nodes:

- a CharacterBody2D at the root, with Motion Mode set to Floating;
- an AnimatedSprite2D named AnimatedSprite2D, with a SpriteFrames that holds every animation;
- a CollisionShape2D with a small rectangle at the feet. Seen from above, only the feet touch the ground.
Motion Mode matters more than it looks. The default, Grounded (motion_mode 0), is made for platformers: a wall below the character is a floor and one above is a ceiling. We pushed a body diagonally into a wall on each side at 80 px a second. In Grounded mode is_on_wall() was true only against the side walls, and the body slid along every wall at 56.6 px a second. In Floating mode (motion_mode 1) all four were walls and it slid at 78.2. Floating is the top-down mode.
Set the sprite's Texture > Filter to Nearest as well. The project's default canvas filter is Linear, which blurs pixel art as soon as it is scaled.
2. Name the animations by direction
Give each animation its state and its direction: idle_down, walk_down_right, attack_up. The script builds those names from what the player does. You don't have to draw all 8: draw down, down-right, right, up-right and up, and the script mirrors them for the three left ones.

Two defaults to change in the SpriteFrames panel:
- A new animation plays at 5 FPS with looping on. Set each one's speed; the walks in our Top-Down Characters run at 8.
- Turn looping off for attacks. In our test a looping walk sent
animation_loopedtwice in 70 frames andanimation_finishednever. With looping off,animation_finishedcame once and the sprite stopped on its last frame.
3. The 8 direction movement script
Attach this to the CharacterBody2D. It uses Godot's built-in ui_ actions, so it runs in a new project with no setup: the arrow keys, a gamepad's D-pad and left stick, and Enter or Space to attack.
extends CharacterBody2D
@export var speed := 80.0
# 45 degrees apart, clockwise from the right (y points down in Godot)
const FACINGS := ["right", "down_right", "down", "down_left", "left", "up_left", "up", "up_right"]
var facing := "down"
var attacking := false
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
func _ready() -> void:
sprite.animation_finished.connect(_on_animation_finished)
func _physics_process(_delta: float) -> void:
if attacking:
return
var input := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
if input != Vector2.ZERO:
facing = FACINGS[wrapi(roundi(input.angle() / (TAU / 8.0)), 0, 8)]
if Input.is_action_just_pressed("ui_accept"):
attacking = true
_play("attack_" + facing)
return
velocity = input * speed
move_and_slide()
_play(("walk_" if input != Vector2.ZERO else "idle_") + facing)
func _play(anim: String) -> void:
var flip := false
if not sprite.sprite_frames.has_animation(anim) and anim.contains("left"):
# no left animation drawn: play the right one, mirrored
anim = anim.replace("left", "right")
flip = true
sprite.flip_h = flip
sprite.play(anim)
func _on_animation_finished() -> void:
attacking = false
What we checked in Godot 4.7.2, frame by frame at 60 physics frames a second:
- Diagonals at the same speed.
Input.get_vector()caps its length at 1: right and down together gave (0.707, 0.707). A rawVector2(1, 1) * 80covered 113 px in a second, the capped vector 80. - No
deltain the velocity. Velocity is pixels a second andmove_and_slide()applies the frame time itself: 60 frames at 80 moved the body 80 px. Multiplied bydeltafirst, 1.33 px. - 8 facings from the angle.
angle()is 0 to the right and 90 degrees straight down. Divided by 45 degrees and rounded, it indexesFACINGS;wrapi()turns the upper half's negative numbers into the right index (up-left is -135 degrees, so -3, so 5). A stick at 18 degrees faces right, at 27 degrees down-right. - The facing is kept. It changes only while a direction is held, so stopping after up-left plays
idle_up_left, hereidle_up_rightmirrored. play()every frame is safe. With that animation already playing it carries on: an 8 FPS walk went 0, 1, 2, 3, 0 over 40 frames.- The attack plays out. Holding left during it moved the body 0 px. A 4-frame attack at 12 FPS ended after 20 frames, then the walk picked up.
For a sheet drawn in 4 directions, swap the facing line for this one. The bigger axis wins, and an exact diagonal shows up or down:
facing = ("right" if input.x > 0 else "left") if absf(input.x) > absf(input.y) else ("down" if input.y > 0 else "up")
4. Three faults the short script leaves in
The sideways hop. flip_h mirrors the picture inside its own frame, not around the character. We drew one column 5 px from the left of a 16 px frame and rendered it: flipped, it was drawn 10 px from the left. A character whose feet are off the middle of its cell jumps by twice that distance every time it turns. The fix is a cell as wide on both sides of the feet, which means laying the sheet out again.
Letting go of a diagonal. Nobody lifts two keys in the same frame. We held up and left, let go of up, and of left one frame later: the character ended facing left, not up-left. The fix keeps the diagonal for a few frames after a turn to one of its sides.
The feet. An AnimatedSprite2D is centred by default, so the node's position is the frame's middle. Under a parent with Y Sort Enabled (off by default on a Node2D), the character is sorted by its middle, not its feet, and goes behind things too early. Turn Centered off and set Offset to minus the feet's place in the frame.
The fast way: the Godot Animation Scene Builder
The Godot Animation Scene Builder does all of this from your sheet, in your browser, and never uploads your art.
- Drop the character. One sheet, a sheet per animation or loose frames, with the JSON from our packs, Aseprite or TexturePacker if there is one. Every animation is named by state and direction for you. Our 4-way adventurer comes in as 8 animations, idle and walk in 4 directions, in a 16 x 16 cell with the feet at 8, 16.
- Pick 8, 4 or 2 facings. A table shows what each facing plays: its own animation, the mirrored side or the nearest one. Give the adventurer 8 and the diagonals show the side, with a note that 4 may fit better. Rename, split or re-aim any animation.
- Walk it around. WASD or the arrows, Shift to run and J to attack, in a room with two crates, before you open Godot. Set the walk and run speeds (60 and 110 px a second to start with), and tick Isometric ground for half-speed up and down.
- Download the Godot scene. A ZIP with your art as it was, a SpriteFrames where every frame is its own region of the sheet (no Hframes to count), a CharacterBody2D scene in Floating mode with the Nearest filter and a collision box at the feet, the movement script, a test room to press F6 on, and a README.
Its script is the one above with the three faults taken out: the cell is as wide on both sides of the feet, so flip_h mirrors in place; letting go of a diagonal within 6 frames keeps it; attacks and hurts go through play_once(), which sends action_finished. Its input actions are added only when your project lacks them. Every file was checked in Godot 4.7.2.
Open it with a free Gridwright account, made with only your email: every feature works on your own sheets, our three sample characters (the adventurer, an 8-way knight with a sword and a farmer from three sheets) are a click away, and your work is saved. Downloading the Godot scene comes with Pro.
Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.
Start: 3 days for $1 See everything it includesFAQ
How do I make a character face 8 directions in Godot 4?
Take the input vector's angle(), divide it by TAU / 8.0, round it with roundi() and wrap it into 0 to 7 with wrapi(). With the facings listed clockwise from the right, that number is the facing. Change it only while a direction is held, so the character keeps facing that way when it stops.
Why is my character faster on diagonals?
The input vector is longer than 1 there: (1, 1) is 1.414 long. Input.get_vector() caps it at 1, so diagonal and straight moves have the same speed.
Why does my attack animation stop after one frame?
Something plays idle or walk on the next frame. Skip movement until animation_finished fires, and turn looping off on the attack, or that signal never comes.
Walk it before it ships
Open the Godot Animation Scene Builder, drop your sheet and walk the character around before it goes into your game. For characters with the JSON it reads, Top-Down Characters has 4-way ones and Isometric Characters 8-way ones with attacks. More on SpriteFrames in Godot Sprite Sheet Animation, and on sharp pixels in Godot Pixel Perfect Settings. The tool and the packs are part of Gridwright: 44 tools and 150 asset packs, 3 days for $1, then $17 a month.
Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.
Start: 3 days for $1 See everything it includes