How do I know which tile is being hit on collision

Get help using Construct 2

Post » Wed Feb 25, 2015 6:44 pm

So I got around this by

(A) Distributing an X and Y Cordite to each tile instance i created, i.e coordinate 0,0 is the first piece, (I used triangular pieces and placed them by hand because I'm not great at arrays, but it was really simple, just make them then select the row and column and change all the instances of that instance variable X or Y cord. I kind of enjoy this way because I can easily replace the underlying tile with a different shape and make Risk-esque type maps.) Then use this example to call arrays https://www.scirra.com/tutorials/630/building-a-basic-board-game-board-tokens-and-moving-them

(B) Moving the piece to the coordinate of the projectiles end, I believe I used the Snap to Add on (you can also just move the object to at a speed (i.e ranged attacks), then simple call up the coordinates by either the tiles X/Y of the piece the player clicked on or the AI wants to go to. I use ghost pieces for selection but you could independently call the tiles each time

(C) Then make that piece check what it is overlapping and set it's (instance variables) CurX, CurY to the current cells (also independently stored from the array) then set the explosion on that tile once it hits. Or whatever :P I use it primarily for movement, but it does work for animations.

Here is my example from when I first did Enemy Movement, it should be the most simple example

https://drive.google.com/file/d/0Bz7FEsAe5hXcWEp0LWVfODFab00/view?usp=sharing

If anybody sees any problems let me know on my drive (I think you can post anon on my drive to.), I may have them fixed in a later version but let me know this should be pretty self contained at this point.
B
9
S
2
Posts: 54
Reputation: 638

Post » Wed Feb 25, 2015 7:11 pm

What's wrong with just having the tilemap layer that's visible and the collision layer that's invisible, and just make sure the collision layer matches up with the visible sprites?
B
6
S
1
G
1
Posts: 95
Reputation: 910

Post » Wed Feb 25, 2015 7:42 pm

That's what mine does, and then it deletes the background sprites underneath it if that tile doesn't exist (Unused instance variable) I also have walls in there. They just all happen to look the same in this build
B
9
S
2
Posts: 54
Reputation: 638

Post » Thu Feb 26, 2015 10:43 am

So, nobody has an idea how to get the right tile on collision ? :(
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Thu Feb 26, 2015 1:07 pm

Well I think i managed to do it after too much hours because my brain can't handle so much X and Y.

http://canapin.com/construct/tolilo/10/

On a collision, it tests every tile in a square of 1 tile around the tile at impact if they are not empty (blue squares).
Then it tests the distance between these tiles and the tile at the impact. The shortest distance leads to the closest tile (red one).

I used dummy sprites instead of directly using the tiles data (X and Y) because it was easier for me to understand how it works visually.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Thu Feb 26, 2015 4:03 pm

Haven't read all the replies. So this might not be what you mean, but how I understood the original question. But in that case you can just ignore it :D

Here is a simple example of how to get the tile.

Image

Image

(Be advise that the tilemap at row 0 for both X and Y is empty so its not an error that it seems like it should be tile 3,7, its just me that didn't put any tiles in that row, so the white area around the tiles are actually row 0)

If you want the coordinate in X,Y you can just convert the TileX and TileY to that.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Feb 26, 2015 5:22 pm

Do you think it works with phycics behavior where, I think, the bullet wouldn't overlap the tiles but just collides with it ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Thu Feb 26, 2015 6:08 pm

Coin-coin le Canapin wrote:Do you think it works with phycics behavior where, I think, the bullet wouldn't overlap the tiles but just collides with it ?

Cant see why it shouldn't, it just uses the position of the bullet. So if its the same with the physics behaviour it should work I think. But I haven't worked that much with that behaviour so you would have to test it to be sure.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Feb 26, 2015 7:09 pm

Can you share your capx ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Thu Feb 26, 2015 7:41 pm

What you see is the whole Capx
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: jatin1726, Resslx and 38 guests