Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var Mpos = get_global_mouse_pos()
- var LMB_ON = false
- #Mpos is Mouse Postion
- #LMB_ON is Left Mouse Button is pressed, I decided to do a var so I can check it in Procces(Delta) then call it to use anywhere else.
- func _ready():
- set_process(true)
- set_process_input(true)
- func _process(delta):
- Mpos = get_global_mouse_pos()
- #Updates the Mpos on Current pos
- if Input.is_mouse_button_pressed(BUTTON_LEFT):
- LMB_ON = true
- else:
- LMB_ON = false
- #checks if Left Mouse Button is Pressed, if is turn var LMB_ON and then off when done.
- #print (Mpos)
- #print (LMB_ON)
- # A few Printers to check if the vars are working
- func _on_KinematicBody2D_mouse_enter():
- #useing a node connection to check for mouse in the area of the sprite
- print ("touched")
- if LMB_ON == true:
- print ("pressed")
- self.set_pos(Mpos)
- #now if the mouse is in the area and the LMB is on then it should keep itself attached to the Mpos.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement