0 votes

I'm trying to make a prototype for a turn-based dungeon crawler. I say "turn-based" because I want the player to move tile by tile without necessarily using a _process function.

I've looked at the 2D Role Playing Game Demo. I notice it uses the TileMap for every game entity; walls, player, NPCs, and items. Before moving to the next tile (of the given direction), the game checks whether it contains a wall tile or another object, using the TileMap.get_cellv() function.

So far so good.

But what if I wanted to have a Node2D (or some subclass of that) for NPCs/enemies and items, instead of the counter-intuitive TileMap? I know the target position, but I can't seem to find a way of checking whether that position contains a node (while I can check a TileMap for a specific tile).

And I'm guessing many will suggest I use _process and Area2Ds and signals. But I'd rather not, since it's a game where everything moves step by step and I want to keep it to the bare essentials.

Note: Area2Ds only seem to work asynchronously (aka with signalling), while get_overlapping_areas() doesn't work properly either.

Godot version 3.5.stable.official
in Engine by (15 points)

Thank you both. I ended up using the TileMap as used in the demo and it's not that bad after all.

2 Answers

0 votes

Designs like these usually require a simple approach to keep track of all objects of the tilemap manually, using a dictionary { Vector : tile content }
You will update it whenever something is created on the map or something moves, and will read from it before attempting to move, just like in the demo.

by (8,099 points)
0 votes

Try using raycast to detect in the direction you're moving towards. It will detect every thing in that next tile without having to keep track of it in a loop. Which can decrease game performance.

Here is a good youtube video explaining something similar to what you're looking for:
https://www.youtube.com/watch?v=Z0w9Jviq57c

He shows you how to use a ray cast to detect what is in the direction of the character, then to do something accordingly (just stop walking if it's a tilemap item or ignore if it's any thing else, in this example) And the characters stay on grid. Never moving off it.

by (22 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.