0 votes

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?

in Engine by (12 points)

Your screenshot link is broken.

1 Answer

0 votes

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.

by (114 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.