Topic was automatically imported from the old Question2Answer platform.
Asked By
Noob_Maker
Old Version
Published before Godot 3 was released.
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:
set_pos(get_global_mouse_pos())
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 mouse_over: set flag_dragging=true
somewere in the update code:
while dragging == true
set_pos …
and on right mouse button up
flag_dragging=false
Thanks but when I type in set flagdragging = true is says that it expecting an end statement after the expression
Noob_Maker | 2017-08-05 15:09
filedragging is a variable i defined myself in the script. It belongs to the object you want to drag.
Example:
extends PanelContainer
var dragging = false
func _ready():
self.set_process(true)
self.set_process_input(true)
#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
self.set_process_input(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:
self.set_pos(...)
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
self.set_process_input(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.