How do I know which tile is being hit on collision

0 favourites
From the Asset Store
slide the tiles to fill the board.60 awesome levels.
  • R0J0hound, I slowed the bullet down, but collision does not appear. No visual change.

    I also added an unsolid tilemap2 to the list.

    When a bullet is collided with a tilemap, we should see the following:

    1) The tile of tilemap is erased

    2) and is replaced with a tile of unsolid tilemap2 ( I used "set a tile" trick, not sure if it is right).

  • I have a similar problem here :

    Left click to shoot (X if you have a plugged in gamepad).

    The bullet is supposed to bounce of the green tiles, but sometimes it targets the next tile.

    Plus, the bullet and the tilemap having a physic behavior, sometimes the bullet bounces of a tile but the event "bullet on collision with tile" is not triggered, that's why it sometimes bounces on purple tiles even if it shouldn't.


    (event 2 tests if it is a green tile)

    What should I do ?

  • heliogame

    The actions you're using to erase/set a tile are using


    but the actions are asking for tile column and row not layout x and y. So if you change it to:


    it works.

  • le Canapin

    map.tileAt() is just getting the tile the projectile's center is currently on, which will almost always be -1 or empty because when it collides with the tilemap only it's edge is touching a tile.

    "on collision" may not be triggered because the physics already resolved the collision and it is no longer overlapping. You'd have to test this to be sure, since I thought that the physics behavior would trigger it directly.

  • How dumb I am.

  • 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

    (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 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

    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.

  • 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?

  • 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

  • So, nobody has an idea how to get the right tile on collision ?

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

    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.

  • 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

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

    (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.

  • Do you think it works with phycics behavior where, I think, the bullet wouldn't overlap the tiles but just collides with it ?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Can you share your capx ?

  • What you see is the whole Capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)