| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | czakita |
I’m very new to Godot and programming things that are not CYOA games.
I have a dress-up mechanic in my game. I was able to set drag&drop script (copied from this forum, I believe), looking like this:
extends StaticBody2D
var can_drag = false
var grabbed_offset = Vector2()
func _input_event(_viewport, event, _shape_idx):
if event is InputEventMouseButton:
can_drag = event.pressed
grabbed_offset = position - get_global_mouse_position()
func _process(_delta):
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and can_drag:
position = get_global_mouse_position() + grabbed_offset
It works until there are two collision shapes overlapping. Then clicking in the overlapping area affects all the overlapping nodes, and I would like it to affect only the one on the top. How do I approach this?