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: 383
Reputation: 12,262

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: 383
Reputation: 12,262

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.
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

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: 383
Reputation: 12,262

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
402
S
238
G
89
Posts: 24,632
Reputation: 196,041

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: 383
Reputation: 12,262

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
94
S
33
G
118
Posts: 5,393
Reputation: 75,847


Return to How do I....?

Who is online

Users browsing this forum: dop2000, LunaticCat and 7 guests