#local_to_map not working with Tilemap

19 messages · Page 1 of 1 (latest)

tulip obsidian
#

Hi all,

I am following a Godot 3 tutorial series but trying to recreate in Godot4. I am stuck trying to make the room's walls close in when the player steps on a detection zone. The detection zone is working as the enemy summoning part is working, but the local_to_map function does not appear to be pulling from the tilemap properly. Relevant screenshots and code snippets are attached.

hazy cradle
#

What's the global position, and what's the result of local_to_map on that global position? And what do you expect to get?

#

Note that if your tilemap isn't at 0, 0 then you'll need to convert from global position to the tilemap's local coordinates using tilemap.to_local

tulip obsidian
#

This is the setup of the tilemap, I just have two of the tiles selected

#

The local_to_map seems to be returning the correct coordinates: (6,7) and (7,7)

#

Or should it be returning the coordinates of the tilemap itself? A bit confused on that part

#

@hazy cradle The tutorial I was following kind of glossed over the tilemap setup, so that might be an issue

silver magnet
#

it looks like you're setting a column of two cells to the tile at atlas coordinate 0,0. set_cell's second argument is for the position of the cell you want to modify, and the fourth argument is for the atlas coordinate of the tile you want to set that cell to.

hazy cradle
#

Yeah^
The tile source you showed only has tiles at 7,4 and 2,7

tulip obsidian
#

Ohhh I think I see now. I did not understand the purpose of the Vector2i.ZERO and it's likely due to the tutorial setting up the atlas in a different way

#

Let me play around with it a bit

tulip obsidian
#

@hazy cradle @silver magnet Sorry to bug you, is this an implementation that should work? Still getting nothing to show up 😦

hazy cradle
#

the value you've set to 1 and 2 is possibly wrong

#

it should match the number you see in the tileset dock here:

#

that's the third parameter to set_cell

tulip obsidian
#

Aha! You're right that worked

#

Thanks for the help!

hazy cradle
#

hooray