Godot-8-Direction-TileMap-Layer-Script
This project demonstrates smooth 8-direction movement in a 2D isometric-style world, using a 4-direction animated sprite sheet.
It mimics the classic movement style of Ultima Online โ the player remains centered while the world scrolls underneath.
The scene uses Godot 4.5.1, with a simple tilemap, a camera-centered player, and a GDScript that handles input, animation, and direction mapping.
- 8-direction movement via right mouse button
- Uses a 4-direction sprite sheet (N, E, S, W)
- Maps diagonals to the nearest facing direction
- Player stays centered; world moves below
- 3ร3 subgrid for smooth fractional stepping
- Lightweight 2D implementation (no 3D or physics)
- Clear and commented
player.gdscript
Universe Node2D
โโโ TileMapLayer (TileMapLayer)
โโโ Player Node2D
โโโ AnimatedSprite2D (Character animation)
โโโ Camera2D (Centers on player)
TileMapLayerโ handles terrain and tile visualsPlayer Node2Dโ main player logicAnimatedSprite2Dโ uses 4ร4 sprite sheet with N/E/S/W rowsCamera2Dโ keeps the player centered at all times
res://
โโโ assets/
โ โโโ player/
โ โ โโโ male425.png # 4ร4 sprite sheet (N,E,S,W)
โ โโโ terrain/
โ โโโ dirt-tile-88-v0.png # base tile
โโโ scenes/
โ โโโ universe.tscn # main scene
โโโ scripts/
โ โโโ player.gd # movement + animation script
โโโ icon.svg
โโโ main.tscn
- Open the project in Godot 4.5.1 (or later).
- Load
scenes/universe.tscn. - Verify the
spritesheet_pathinplayer.gdpoints tores://assets/player/male425.png. - Check the Import Settings for
male425.png:- Filter: Off
- Mipmaps: Off
- Repeat: Disabled
- Then click Reimport
- Run the project โ right-click and hold to move the player around the map.
| Direction (Grid) | dir8 Index | Animation Row | Facing (on Sprite) |
|---|---|---|---|
| East | 0 | 1 | E |
| Southeast | 1 | 2 | S |
| South | 2 | 2 | S |
| Southwest | 3 | 3 | W |
| West | 4 | 3 | W |
| Northwest | 5 | 0 | N |
| North | 6 | 0 | N |
| Northeast | 7 | 1 | E |
Each diagonal uses the nearest cardinal animation row from the 4-direction sprite sheet.
This demo and the included player.gd script are released under the MIT License.
Youโre free to use, modify, and redistribute it for your own Godot projects.
(The player stays centered while the tilemap scrolls underneath.)
Created with โค๏ธ in Godot 4.5.1