Skip to content

hexagonal_map: Add turn-based movement mode#1239

Open
idbrii wants to merge 4 commits intogodotengine:masterfrom
idbrii:hex-turnbased
Open

hexagonal_map: Add turn-based movement mode#1239
idbrii wants to merge 4 commits intogodotengine:masterfrom
idbrii:hex-turnbased

Conversation

@idbrii
Copy link
Copy Markdown
Contributor

@idbrii idbrii commented Aug 25, 2025

Games with hexagonal maps usually want characters to move between tiles on the grid, so I added another movement option that makes the troll from tile to tile like a turn-based hex game. It still uses WASD controls (you need to press multiple keys to hit all 6 directions). Works well on gamepad too.

Additionally, the current move_and_slide troll doesn't really interact with the world, so I made it stop before leaving the grid. This also acts as a demonstration of how to get the tile id for interacting with objects represented by valid tiles.

I also converted TileMap to TileMapLayer.

No untyped_declaration warnings.

Demo:

godot-hexmap.mp4

Copy link
Copy Markdown
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not call these turn-based and real-time movement. These should be called tile-based and free movement. You can have movement be done on tiles without being turns, and being real-time doesn't inherently indicate that movement is freeform.

The code needs to follow the GDScript style guide: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_styleguide.html

All files need to be snake_case, so for example, gridlayer.gd needs to be renamed to grid_layer.gd.

@aaronfranke
Copy link
Copy Markdown
Member

See also PR #1085 which adds hexagonal navigation, I wonder if all of these should be in one demo.

@aaronfranke aaronfranke marked this pull request as draft October 3, 2025 02:02
@idbrii idbrii force-pushed the hex-turnbased branch 4 times, most recently from 1f219ec to 940feee Compare October 5, 2025 18:04
@idbrii
Copy link
Copy Markdown
Contributor Author

idbrii commented Oct 5, 2025

Applied all the style changes and renaming to "tile-based and free movement".

I believe I correctly merged with #1258 (kept uid from master).

See also PR #1085 which adds hexagonal navigation, I wonder if all of these should be in one demo.

I agree it'd make sense to combine them in the future. Maybe once this PR is merged that PR could add their features to this demo?

@idbrii idbrii marked this pull request as ready for review October 5, 2025 18:31
@idbrii idbrii requested a review from aaronfranke October 5, 2025 18:31
@aaronfranke
Copy link
Copy Markdown
Member

With the current behavior of the demo, I find it very difficult to move up-left or down-right. If I try to move down-right, and I don't press the keys at exactly the same time, I end up moving down or right. I think it should not try to move when the input direction is close to being in-between two others, such as a right input being ambiguous between up-right and down-right, and instead a right input should wait until an up or down input is received.

@idbrii
Copy link
Copy Markdown
Contributor Author

idbrii commented Oct 10, 2025

@aaronfranke What if instead, you select a direction and then press a key to confirm movement? I think that's more classic hex movement behaviour. Mouse picking an adjacent destination would also be more typical (but maybe for a future PR).

I wasn't sure how much complexity is okay in these demos, but if that's fine then I think the more expected movement for hex is a better choice.

Games with hexagonal maps usually want characters to stay within the
grid, so add another movement option. This troll has no physics and uses
tweens to move. Instead of collision, it uses tile values to determine
where they're allowed to go.

You aim your movement and then confirm with a separate key, which adds
complexity over the free movement but ensures movement always matches
intent.
Move troll's root pivot to line up with their collider. This makes their
global_position a good representation of where they are.

Add check for moving to an invalid tile and undo our move. In my tests,
this isn't less smooth than skipping the move_and_slide if
(global_position + velocity * dt) is an invalid tile and allows sliding
to resolve us to a slightly different position.
@idbrii
Copy link
Copy Markdown
Contributor Author

idbrii commented Dec 22, 2025

@aaronfranke I've updated the tile troll movement so you press Space/A to confirm movement.

Use get_vector when building a Vector2 from input so it applies the
deadzone.

Increase the deadzone on all move inputs.
Add mouse click to move_confirm and now you can wasd, mouse point, or
gamepad LS to aim your troll.
@idbrii
Copy link
Copy Markdown
Contributor Author

idbrii commented Dec 24, 2025

I added mouse aiming too. It was easier than expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants