• 0 Posts
  • 5 Comments
Joined 2 years ago
cake
Cake day: June 29th, 2024

help-circle




  • You could have your Drag Box use the Area2D class and listen for it’s events like this: (input_pickable need to be set to true)

    class_name DraggableBox
    extend Area2D
    
    var mouse_inside: bool = false
    
    func _ready():
      mouse_entered.connect(_on_mouse_entered)
      mouse_exited.connect(_on_mouse_exited)
    
    func _process(delta: float):
      if (not mouse_inside): reuturn
      if (Input.is_action_pressed("name_for_action_with_mouse_click"):
        #handle your object movement
      if (Input.is_action_just_released("name_for_action_with_mouse_click"):
        #handle letting go of the object
    
    func _on_mouse_entered():
      mouse_inside = true
    
    func _on_mouse_exited():
      mouse_inside = false