Drag and drop controller

An asset by programaths
The page banner background of a mountain and forest
Drag and drop controller hero image

Quick Information

0 ratings
Drag and drop controller icon image
programaths
Drag and drop controller

This script node permit to handle drag and drop of any nodes in a specific group of your choice.It handles correctly nodes that overlaps by picking the topmost one. It will also raise nodes that are bellow other nodes so they "fly over" when you drag them.

Supported Engine Version
3.1
Version String
1.0.0
License Version
MIT
Support Level
community
Modified Date
5 years ago
Git URL
Issue URL

Use

  1. Add the DragDropController node in your scene.
  2. In the inspector, fill in Drag Group with the name of the group containing nodes you want to be draggable, by default, the group is named "draggable".
  3. (optional) In the node that can be dragged, you can create two methods : on_drop and on_drag_start

on_drop

Called when the node is dropped. Return "false" to prevent drop. Do not return anything (no return in your function) or return true to allow drop.

Here is an example of implementation to check if you are dropping in a free space:

onready var previous_position = position
func on_drop():
    position = position.snapped(Vector2(64,64))
    yield(get_tree(),"idle_frame")
    yield(get_tree(),"idle_frame")
    if get_overlapping_areas().size()>0:
        print("col!")
        position = previous_position
    else:
        print("no col")
        previous_position = position

on_drag_start

Called when the node begin to be dragged. (if multiple nodes are stacked, only the topmost node will be dragged)

This script node permit to handle drag and drop of any nodes in a specific group of your choice.

It handles correctly nodes that overlaps by picking the topmost one. It will also raise nodes that are bellow other nodes so they "fly over" when you drag them.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Drag and drop controller icon image
programaths
Drag and drop controller

This script node permit to handle drag and drop of any nodes in a specific group of your choice.It handles correctly nodes that overlaps by picking the topmost one. It will also raise nodes that are bellow other nodes so they "fly over" when you drag them.

Supported Engine Version
3.1
Version String
1.0.0
License Version
MIT
Support Level
community
Modified Date
5 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers