Issues with collisions in Area2D

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

I created a target in Godot that has a CollisionShape2d and an Area2D. I have it set up to queue_free() when you click on it with the mouse

func _on_Area2D_input_event(_viewport, event, _shape_idx):
	if event is InputEventMouseButton:
		if Input.is_action_pressed("ui_click"):
			# don't want it to play every time we click
			if (play_once == 0):
				# coroutine keeps queue_free() from happening before sound is over
				yield(play_sound(), "finished")	
			play_once = 1
			emit_signal("target_hit")
			queue_free()

when I create a scene with just the target in it I can click anywhere in the Area2D and it will disappear as expected. But when I added it to my level one scene it only appears to respond to clicks when I click directly in the center of the target. I’m unsure what is causing this behavior. I have a few screen shots of the way it looks when I start the scene, and how the target node was created. Does anyone know why this might be happening?

Your screenshot link is broken.

kidscancode | 2020-03-21 19:22

:bust_in_silhouette: Reply From: a human

Your screenshots are broken, but one solution is instead of using an area2d you could try using the button node, and overlapping it with your target. You could then connect its signal to the target replacing area2d function with the button one. Don’t know if this helps.