#Detecting collision between tilemap and a rectangle

1 messages · Page 1 of 1 (latest)

wary ore
#

How do I detect which tiles in the tilemap are coliding with the rectangle?
I have a tilemap already set, I draw rectangle from mouse inputs.
I already have everything set up, just don't know how to connect the two of them. As in how do I select tiles based on shape of the rect.

snow girder
#

you mean tile map layer right?

#

the tile map node is deprecated fyi

#

okay so what you need to do is get the tile size inside the TileSet property of the tilemap(see docs)

#

than loop over the get_used_cells() method , and check if they are present inside the rectangle

#

if you need info about implementation tell me

wary ore
snow girder
#

you want to check if they are fully inside or only partily

wary ore
#

Was thinking partially. But fully is also a good option.

So far didn't test it but was thinking about checking if rectangle values (when it's dragged) are dividable by tile size, then drawing lines from those points and by that getting point cords on which to check if there are tiles there.

So like creating a mesh inside rectangle that'll then pick all tiles to select.

snow girder
#

is your tile set completly filled??

#

it really depends on what your going for

#

for something that always works you can loop as i suggeste

wary ore
#

Yup, completely filled. I want to do what Rect Tool does in the editor, but in game.

snow girder
#

checking if a rect collides with another is as simple as checking if atleast on corner is inside of the rect(tile)

#

if you need more clarifycation tell me

#

or if i missunderstood your goal

#

also english isn't my first language so sorry

wary ore
snow girder
#

oh

#

the tiles are isometric

#

but its filled

#

so its easier

#

lets do it like this

#

implement a function that checks if a tile is inside a rect

snow girder
#

i am not sure if its efficent