I’m new to Godot and I’m playing around with an isometric tilemap and adding some click events. I’ve got code that successfully determines what tile has been clicked, but what I would like to do is determine what face of the isometric tile has been clicked. Is this possible? I thought perhaps I could use multiple physics layers (1 on each face) and then see if there’s a way to determine what physics layers has been clicked, but I can’t see any methods on the tilemap docs that retrieve physics layers.
In my tilemap script I’m using the following process method for determining clicks:
var tile = local_to_map(get_global_mouse_position());
#something here to get the clicked physics layer?
If it’s 2D isometric tiles with no 3D info, there are two easier ways to do it. The pure math approach of just measuring the x&y distance for the tile origin and figuring which of the triangles was clicked on. If you need a diagram I can draw one, but it’s not hard to figure out.
Or the more involved texture masking for each side, say, you make an extra atlas that matches your tileset and paint each side a diferent color, like, red for left, blue for right and green for top, then when the player clicks, you sample that atlas and based on what you get you’ve determined if that pixel on the tileset is a left right or top pixel. It’s more complicated, but lets you make tiles with complex shaper and get accurate per-pixel sidedness.
Hi, thanks for replying, it is 2D, I’m not sure how I can get the full x&y info as with the code above tile.x and tile.y are always whole integers? Is there another method I can use to get this information?
You have to determine the position of the tile on the screen to subtract it from the position of the mouse on the screen so you get the local position of the mouse on the tile. Something like
camera.position - tile_coord * tile_size - event.global_position where the even is a mouse click event, but it depends on how your scene is set up, so it’s up to you to figure out what exactly factors into the tile position on the screen (like wether you have a scaled viewport/zoom or an offset tilemap etc).