When you press certain buttons in my game (a 2d puzzle platformer), the tilemap (but character and maybe enemies and objects) is flipped horizontal or vertically and that can cause problems. The player always has to be in the nearest free space, being the priorities up and down (depending on the position of the center of the collision shape, it will go to one direction or the other (if in the middle of the tile, then up) ) and left or right if there's no space in the previous directions.

I do not know if it would work as I have never tried this, but you could convert the player’s position to a tile index using world_to_map function. Then you could check to see if that tile is empty (empty=no collision ideally) and if it does, move the player to that tile. If the tile isn’t empty, then you could use the tile position of the player and search surrounding tiles in an increasing radius, checking for empty tiles. Once you find an empty tile, you could then move the player to that position.

Again, I’ve not done this myself, but I think it might work.

use global_position?

2 years later