0 votes

So I am working on a drag and Drop mechanic which ALMOST works. and by that I mean when the object is in the air but I can only hold onto it for a split second WHEN IT IS IN THE AIR(in other words not colliding with anything). I don't know what's causing this. It might be how I said to getting the position of the mouse. Other than that I have no clue.

Here's the script:

extends Node2D
var Click = Input.is_action_pressed("Interaction")
var Ready = null

func _ready():
    set_fixed_process(true)#I used this when I was testing the main aspect of what I want the object to do

func _on_Block_mouse_enter():
    Click = Input.is_action_pressed("Interaction")
    if Click == true:
in Engine by (83 points)

1 Answer

0 votes

You only check "mouse_enter" ?
mouse enter will only fire once you enter the object. You have to leave the object and reenter it again so it can fire again.

I did drag an drop this way: when right mouse button down and mouseover: set flagdragging=true

somewere in the update code:
while dragging == true
set_pos ....

and on right mouse button up

by (291 points)

Thanks but when I type in set flagdragging = true is says that it expecting an end statement after the expression :/

filedragging is a variable i defined myself in the script. It belongs to the object you want to drag.


extends PanelContainer

var dragging = false

func _ready():

#left click handeling
func on_input(event):
    if event.type == InputEvent.MOUSE_BUTTON and event.pressed and event.button_index == BUTTON_LEFT:
                #set dragging true
        self.dragging = true

#move and release handeling
func _input(event):
        #here i check if draggin is true, otherwise the panel will always follow your mouse
    if event.type==InputEvent.MOUSE_MOTION and dragging:
    if event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and not event.pressed:
                #when we release the left mouse button, we dont want to drag anymore
        self.dragging = false

since i hande my code within the object i do not need to check mouseover because on_input(event): will only fire if the mouse is over my panel.

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.