How to Change a Tilemap Depending on What is Around It

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DaZel77

I have a base TileMap used for the floor and walls and another TileMap for spikes in my game. Is there a way to change the floor tiles depending on if there is a spikes tile above it?

:bust_in_silhouette: Reply From: Inces

Take a note, that tile map cells are identified by vector2. This vector value corresponds to local tiles positions in 2d space.
If You take any tile by its map position, than get_cell(tile + vector2(1,0)) is the tile to the right, and get_cell(tile +vector2(0,-1)) is the tile above it. Knowing this You can change your tile with set_cell(tile)