How do I test if a position is overlapping a tilemap?

0 favourites
  • 8 posts
From the Asset Store
Enchanted Forest & Cave 16x16 Tilemap with Environment Sprites
  • I want to test if my player is above a tile, but I can't have it catching multiple tilemaps (because I have tilemaps next to each other but not overlapping). So I want to use just the position of the player's origin.

  • You can use the "pick overlapping point" system condition to select the tilemap that the player sprite's x,y is overlapping, and then use the tilemap's PositionToTileX PositionToTileY expressions to pick the tile:

    Note that the player's origin would need to be centred in order to pick the tilemap that the player was most over. If you can't have the player origin in the centre then you can add an extra image point in the centre and use those co-ordinates to pick the tile map (using player.ImagepointX(1), player.ImagepointY(1))

  • This fixes my problem but creates new ones. I want to take a different approach. Is it possible to only pick the tilemap closest to the player?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It depends upon the dimensions of your tilemaps - if one of the maps is larger than the other then the smaller one may be picked as being closer, even if the player overlaps more of the larger, because the origin of the smaller tilemap is nearer to the player's origin. There is also another issue: the tilemap object's origin is in the top left corner and can't be changed, so in order to find the centre you would need to add 0.5*tilemap.width to tilemap.X and 0.5*tilemap.height to tilemap.Y.

    Could you explain what the new problems are? It will be easier to suggest solutions if you can outline all of the constraints.

  • Basically my character uses these tilemaps (8x8) to climb. I created a system that would make them move along with the tilemap when holding shift and the ability to climb around it as well. When I used the player col box to test which tilemap they were over, and it picked up multiple tms, it would duplicate my player for some reason. So I decided to use just image point, which stopped duping but then made the player completely stop when they reached a corner of the tilemap, making them unmovable. Now I want to pick tms using just which one is closest and if it's overlapping

  • This was the best I could do based on your example:

    The meat of it is in event 5. I have a variable on the player that records the tilemap UID when you start climbing; if the condition checks that the player is overlapping more than one tilemap it picks the nearest and checks to see if its UID matches the saved tilemap UID on the player variable. If it doesn't then the saved UID and movement modifiers are updated.

    Hope that helps! :-)

  • Works! Had to do some tweaks but did the job, thanks!

  • You're welcome :-)

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