Skip to content

MichaelTen/Godot-8-Direction-TileMapLayer-Script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Godot-8-Direction-TileMapLayer-Script

Godot-8-Direction-TileMap-Layer-Script

Godot 4.5 Isometric 8-Direction Movement Demo (4-Direction Sprite)

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.


๐ŸŽฎ Features

  • 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.gd script

๐Ÿงฉ Node Tree


Universe Node2D
โ”œโ”€โ”€ TileMapLayer            (TileMapLayer)
โ””โ”€โ”€ Player Node2D
โ”œโ”€โ”€ AnimatedSprite2D    (Character animation)
โ””โ”€โ”€ Camera2D            (Centers on player)

  • TileMapLayer โ†’ handles terrain and tile visuals
  • Player Node2D โ†’ main player logic
  • AnimatedSprite2D โ†’ uses 4ร—4 sprite sheet with N/E/S/W rows
  • Camera2D โ†’ keeps the player centered at all times

๐Ÿ“ Folder Structure


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


โš™๏ธ Setup Instructions

  1. Open the project in Godot 4.5.1 (or later).
  2. Load scenes/universe.tscn.
  3. Verify the spritesheet_path in player.gd points to res://assets/player/male425.png.
  4. Check the Import Settings for male425.png:
    • Filter: Off
    • Mipmaps: Off
    • Repeat: Disabled
    • Then click Reimport
  5. Run the project โ€” right-click and hold to move the player around the map.

๐Ÿง  Direction Mapping Overview

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.


๐Ÿ“œ License

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.


๐Ÿ“ธ Preview

image

(The player stays centered while the tilemap scrolls underneath.)


Created with โค๏ธ in Godot 4.5.1

About

Godot-8-Direction-TileMap-Layer-Script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published