Interaction between two overlaping 2D elements

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BigBackPack

I try to make a 2D top down turn based game. In every turn the player can move 5 steps and with each step he is entering a new tile/element which should trigger a new event.

Now I try to find the best way to check which tile was stepped on in order to trigger the right event. Here is what I tried so far and the problems I faced so far:

  1. I used a tile map to create a grid of tiles the player can step on → Problem: don’t see a way to distinguish the different types of tiles one from another in a TileMap. So player can interact with a tile but does not know what kind of tile he stepped on exactly.

  2. I also tried a 2D Array to generate a 100x100 elements big grid, with all elements having there own collider → Problem: Even though I can now get specific informations about every element entered by the player the game is already crashing while loading. I guess creating a grid of 100x100 elements with colliders on every single element is simply to much for godot…

Is there any better way to this? I open to any suggestions that might help.

:bust_in_silhouette: Reply From: jtarallo

Hi, i’ll give you suggestions for both approaches:

  1. Manually create your tiles as nodes. You can do this with no problem loading a texture in your scene, setting its vframes and hframes and you have a tilemap with coordinates that you can use in N sprites. You can create a scene called TileExtended or anything you’d like to name it, attach a script to it to store its properties, give it a texture property and set it to your loaded texture from your scene. Give your TileExtended a type so that you know which coordinate to display in your Tile scene sprite (you’d need to map the coordinates with their types somewhere, maybe in a globals file so it is accessible from anywhere). Then you can instance it N times, set its texture, type and position and you have the map ready.

  2. If you want to use colliders (which I don’t recommend for this, as I think it is not really needed since you don’t need physics simulations for anything you mentioned), you should limit the colliders to the objects which are displayed in the scene .So if you loaded a 100x100 grid, I don’t thing you’ll be seeing 10k tiles at the same time, so you should try and optimize to which tiles are colliders added, and which tiles are shown.

I’d go with option 1 which gives you flexibility, and for knowing on which type of tile the player is on, knowing it’s a turned based affair, i’d go about it incrementally checking adjacent tiles to the player on each turn.

Hope you find this of use. Good luck!

Thanks a lot. That is very helpful :slight_smile:

BigBackPack | 2020-06-08 19:39

You’re welcome. If you don’t have further doubts, it’d be nice if you’d mark the question as resolved and choose the answer :slight_smile:

jtarallo | 2020-06-08 19:58