Are you raycasting directly using the direct space state (like in this page on the documentation) or are you using Raycast2D nodes?
If you are raycasting directly using direct space state, there are a couple of ways you can determine what you are raycasting with. Here are a few ways you can do it:
var result = space_state.intersect_ray(origin_position, end_position)
if result:
# Check using the name:
if result["collider"].name == "TileMap":
print ("Hit tilemap!")
# Check using a group
if result["collider"].is_in_group("Group_TileMap") == true:
print ("Hit tilemap!")
# Check if what you hit is of the tilemap type
if result["collider"] is Tilemap:
print ("Hit tilemap")
If you are raycasting using the Raycast2D node, then you can use the following code to detect if you are colliding, get the object you are colliding with, and then determine if it is a tilemap:
var raycast_node = get_node("Raycast2D")
if raycast_node.is_colliding():
var object_collided_with = raycast_node.get_collider()
# Check using the name:
if object_collided_with .name == "TileMap":
print ("Hit tilemap!")
# Check using a group
if object_collided_with .is_in_group("Group_TileMap") == true:
print ("Hit tilemap!")
# Check if what you hit is of the tilemap type
if object_collided_with is Tilemap:
print ("Hit tilemap")
Also: Welcome to the forums!