How do I get the hit cell (tilemap)

Get help using Construct 2

Post » Thu Dec 29, 2016 5:57 am

Hi,

how can i calculate the hit cell (col/row) of a tilemap (on collision)?

Image

mercuryus
Image Image Image
B
43
S
22
G
15
Posts: 387
Reputation: 12,270

Post » Thu Dec 29, 2016 6:35 am

You can use the tilemap method positionToTileX and positionToTileY to get tile position (col/row) from screen coordinates.

it would be something like

col : tilemap.positiontotileX(sprite.x)
row : tilemap.positiontotileY(sprite.y)
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Fri Dec 30, 2016 5:28 am

This returns the cell of the colliding sprite but not the cell the was hit :(
Image Image Image
B
43
S
22
G
15
Posts: 387
Reputation: 12,270

Post » Fri Dec 30, 2016 9:13 am

All I can think of is a rather terrible workaround.

Limitations include really fast balls not registering properly (because they've bounced off and are not overlapping anymore) and slightly inaccurate detection.
Here's the capx.

In short, I moved a set of 8 hit detection sprites to stay on the tiles surrounding the ball. When the ball hits the tilemap, it erases the tiles the hit detectors were on at that point.
ImageImage

Take a look at my itch.io games
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

Post » Fri Dec 30, 2016 1:38 pm

clever solution but a bit too 'fuzzy' for my needs ;)

@ashley: please add this event/function/property to the tilemap object.
Image Image Image
B
43
S
22
G
15
Posts: 387
Reputation: 12,270

Post » Sat Dec 31, 2016 12:22 pm

This is similar to "getting the point of a collision between two objects" - objects don't collide at a point, they have an overlapping region. So in fact the collision would intersect a patch of tiles.
Scirra Founder
B
408
S
242
G
92
Posts: 24,916
Reputation: 198,680

Post » Sun Jan 01, 2017 9:51 am

Would it be possible the provide the overlapping region for (each) collision?
Image Image Image
B
43
S
22
G
15
Posts: 387
Reputation: 12,270

Post » Sun Jan 01, 2017 8:51 pm

Here's some more ideas on how to get the overlapping tiles:
get-the-x-and-y-of-a-collision-point_p1025697?#p1025697

You can probably get exactly like that pic by first using the raycast plugin to get the collision point then using the idea above to get the hit tile.
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests