Destroy tilemap tiles in a circle

Godot Version

Godot 4.2.1


I am trying to add explosives to my game which uses a tilemap, How can I destroy tiles in a tilemap in a circle, with a specified radius? I originally had it so that 10 raycasts were created, all branching out from the center of the circle, but for some reason the rays would not collide with the tilemap, despite being children of the same node, and having the same collision layer. is there a solution to this, or is there a better way to destroy tiles in a circle?

retrieves all tiles within a rect. then check the distance from the center of the explosion to each tile.

extends Sprite2D
var m_sprite:Sprite2D
func _ready():
	# find sprite node named "A"
	m_sprite = get_parent().find_child("A")
func _process(delta):
	#distance between sprites
	var v_distance : float = global_position.distance_to(m_sprite.global_position)

thank you, this helps a lot! would the m_sprite variable be the explosive? also I think you have accidentally left out the script to get tiles in a rect

while the example prints the distance between two sprites, it is really returning the distance between two vector2s. global_position is a vector2, the center of a sprite. here is the same example but with vector2.

if your explosion will have a center. if the explosion is a node2d, such as a sprite, it probably uses global_position for the center.

func _ready():
	var v_distance : float = Vector2(2,1).distance_to(Vector2(10,5))

if you want to get a cell’s global position, use map_to_local then to_global. see the documentation below.