Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

DragDrop2D

An asset by immy
The page banner background of a mountain and forest
DragDrop2D hero image

Quick Information

0 ratings
DragDrop2D icon image
immy
DragDrop2D

DragDrop2D is a simple GDScript framework to allow the player to drag/drop CharacterBody2Ds around.

Supported Engine Version
4.6
Version String
0.1
License Version
MIT
Support Level
community
Modified Date
8 hours ago
Git URL
Issue URL

DragDrop2D

DragDrop2D is a simple GDScript framework to allow the player to drag/drop CharacterBody2Ds around. It supports:

  • Collision bodies for detecting mouse events.
  • Compatibility with 2D physics for bounds checking and constraining where the player can drag to.
  • Tracking drop regions using arbitrary Area2Ds.
  • Validating/filtering drop areas via collision layers or per physics frame.

Usage

  • Create instances of Draggable in your scene.
  • Add at least one CollisionShape2D or CollisionPolygon2D, and set at least one layer (required for mouse detection).
  • Assign collision layer/mask for bounds checking.
  • Add other children to create the desired visuals.
  • Optionally assign a drop mask to detect drop regions.
  • Listen to the events (hovered, drag_started, drop_target_changed, drag_ended) to add logic and visual effects.

Caveats

Because these bodies are characters, they must be the the root of the collision objects. You could probably use RemoteTransform2D to sync the drag/drop with a sibling node, but I haven't tried that. You can also control Draggables in script, but do so in _physics_process via move_and_slide or other physics-compatible ways. Remember to call super() for overriden methods and use caution if attempting to do so while the player is dragging.

I have not tested this for mobile.

Credits

No AI was used when creating this code. While trying to create draggable physics objects, I was inspired by this video from Person Dude Games https://www.youtube.com/watch?v=JW_IyrcYNyQ

DragDrop2D is a simple GDScript framework to allow the player to drag/drop CharacterBody2Ds around.

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
DragDrop2D icon image
immy
DragDrop2D

DragDrop2D is a simple GDScript framework to allow the player to drag/drop CharacterBody2Ds around.

Supported Engine Version
4.6
Version String
0.1
License Version
MIT
Support Level
community
Modified Date
8 hours 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