Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var Mouse_In = false
- var Mpos = get_global_mouse_pos()
- var Objectdrag = false
- # Mouse_In acts as a check switch for if the mouse has entered the object's hitbox
- # Mpos is a simple var to keep check on mouse position, is updated in process
- # Objectdrag is an extra var to keep the mouse from dropping the Object if it is still dragging but escapes the objects hitbox
- func _ready():
- set_fixed_process(true)
- func _fixed_process(delta):
- Mpos = get_global_mouse_pos()
- #Updates the Mpos on Current pos
- if Mouse_In == true:
- if Input.is_mouse_button_pressed(BUTTON_LEFT):
- set_global_pos(Mpos)
- Objectdrag = true
- else:
- Objectdrag = false
- func _on_KinematicBody2D_mouse_enter():
- Mouse_In = true
- func _on_KinematicBody2D_mouse_exit():
- if Objectdrag == false:
- Mouse_In = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement