Hi. New guy here. First post, not sure if I'm in the right place, here goes. This tilemap code takes a collision signal and changes any tile it collides with, and I want to specify some sort of if statement that only changes a specific set of tile names, see line 7 below. I'm stumped. Any idea's appreciated. |edited|

func _on_character_collision(collision)
if collision.collider is TileMap: #receives the collision signal and notifies 
# the tilemap activating a result
var tile_pos = collision.collider.world_to_map(position) # variable of method
# finding vector2 coordinates of sprite collision shape
tile_pos -= collision.normal # sends variable method the direction the 
# collision is signaling
var tile_id = collision.collider.get_cellv(tile_pos) #variable of method connector
# takes collision direction and vector2 coordinates and identifies tilemap index coordinates
var tile_name = collision.collider.tile_set.tile_get_name(tile_id) # variable of 
# method connector gets the tilemap index coordinates and finds the specific
# tile name in the tileset editor
collision.collider.set_cellv(tile_pos, 05) # method takes all that info and installs
# the tile from the tile set in place of another tile of choosing
  • Assuming your code works, it's a simple exception:

    var tile_name = collision.collider.tile_set.tile_get_name(tile_id)
    if tile_name == "01" or tile_name == "02":
         collision.collider.set_cellv(tile_pos, 05)

    If the tiles are actual numerals, then you wouldn't use quotes around them. If it says get_name, they are generally strings.

I'm not sure I follow you, and using numbers for the names confuses me even more. You're trying to rename all of the tiles of that type, or just individual tiles? Or are you changing the tile at that position to a different existing tile?

    duane I edited the code above to specify. I want to change the tile at that position only if it is a specific tile in the tileset and not another. I'm trying to make pacman, with a kinematicbody2d node, and a tile map. I'm trying to make the dot tiles disappear, and still stop collision on the walls. My tilemap has 10 tiles I numbered. I only want tile 01 and tile 02 to be changed to tile 05. So tile 03, 04, 06, 07, 08, 09, and 10 I need ignored, and or no action.

    Assuming your code works, it's a simple exception:

    var tile_name = collision.collider.tile_set.tile_get_name(tile_id)
    if tile_name == "01" or tile_name == "02":
         collision.collider.set_cellv(tile_pos, 05)

    If the tiles are actual numerals, then you wouldn't use quotes around them. If it says get_name, they are generally strings.

    Parenthesis? You beat me with parenthesis! I need to stop drinking. lol