0 votes

I am trying to modify Johnnygossdev's drag and drop script, so that I can use it to have sort of a building spaces, using Area2D draggables and dropzones. I would like to have a draggable with dropzones around, so that I can put another draggable item on one of the dropzones.

Here's the tutorial I am using:

And here's the plan:
The plan

Yet it ends up dragging the right scene and then changing the position of the other.

The result

The question is, how can I make it so the code uses the right draggable element? In the tutorial he seems to be using the setinputas_handled() function but there's not much about it to be found.
I've also thought about using instances but it seems way over my level

Here's the code, only thing I've modified is that I used the dropzone as a child element of the draggable and added a signal for a button release on the dropzone area.

extends Area2D

var previous_mouse_position = Vector2()
var is_dragging = false

func _on_Draggable_input_event(viewport, event, shape_idx):

    if event.is_action_pressed("ui_touch"):
        previous_mouse_position = event.position
        is_dragging = true

func _input(event):

    if not is_dragging:

    if event.is_action_released("ui_touch"):
        previous_mouse_position = Vector2()
        is_dragging = false

    if is_dragging and event is InputEventMouseMotion:
        position += event.position - previous_mouse_position
        previous_mouse_position = event.position

func _on_DropZone_input_event(viewport, event, shape_idx):
    if event.is_action_released("ui_touch"):
        global_position = event.position

Thank you for helping.

in Engine by (12 points)

1 Answer

0 votes

You need to separate the drop zone and the draggable object into separate scenes. If the are in the same scene, they will both move when you move that scene.

by (65 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.