Godot Version
Godot 4.3
Hello all,
Hope all is well. My name is Andy and I am working on a solo project in Godot 4.3. In the game I have heavy use of a ‘drag and drop’ mechanic like in “Case of the Golden Idol”.
I have been copying the code/ layout from this tutorial:
The issue is as follows.
I have created a scene (object.tscn) where the object is draggable and will snap back to the original position if not dropped onto a designated platform. This works via using a " on_mouse_entered" & “on_mouse_exited” function. This works in the scene object.tscn. However when I add the object.tscn scene to the world.tscn scene it just does not want to work anymore. I have noted that in the world.tscn scene when I hover the mouse over the object the “on_mouse_entered” & “on_mouse_exited” signal does not fire. I have checked that the object is
pickable, monitoring is on and the collision layers are all on the same level. I have attached the code below as well as the global script that the object script is referencing.
Scripts + hierarchy’s:
object.gd
###############################################################
extends Area2D
var draggable = false
var is_inside_dropable = false
var body_ref
var offset: Vector2
var initialPos: Vector2
func _process(delta):
if draggable:
if Input.is_action_just_pressed(“click”):
offset = get_global_mouse_position() - global_position
global.is_dragging = true
if Input.is_action_pressed(“click”):
global_position = get_global_mouse_position() - offset
elif Input.is_action_just_released(“click”):
global.is_dragging = false
var tween = get_tree().create_tween()
if is_inside_dropable:
tween.tween_property(self,“position”,body_ref.position,0.2).set_ease(Tween.EASE_OUT)
else:
tween.tween_property(self,“global_position”,initialPos,0.2).set_ease(Tween.EASE_OUT)
func _on_mouse_entered():
if not global.is_dragging:
draggable = true
scale = Vector2(1.05,1.05)
print(“yay its in”)
func _on_mouse_exited():
if not global.is_dragging:
draggable = false
scale = Vector2(1,1)
print(“Aww its out”)
func _on_body_entered(body: Area2D):
if body.is_in_group(‘dropable’):
is_inside_dropable = true
body.modulate = Color(Color.REBECCA_PURPLE,1)
body_ref = body
func _on_body_exited(body: Area2D):
if body.is_in_group(‘dropable’):
is_inside_dropable = false
body.modulate = Color(Color.MEDIUM_PURPLE,0.7)
####################################################################
global.gd
###################################################################
extends Node
var is_dragging = false
#Called when the node enters the scene tree for the first time.
func _ready() → void:
pass # Replace with function body.
#Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta: float) → void:
pass
###################################################################
platform.gd
##################################################################
extends StaticBody2D
#Called when the node enters the scene tree for the first time.
func _ready() → void:
modulate = Color(Color.MEDIUM_PURPLE, 0.7)
#Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta):
if global.is_dragging:
visible = true
else:
visible = false
################################################################
World Scene
TLDR;
I need to get this ‘Drag and Drop’ feature working before I drag and drop my game into the bin.
Thank you in advance for your efforts. All help is appreciated.