I have a script that once a player picks up a RigidBody2D, it will pick it up and follow the mouse. However, Once I let go, the sprite doesn't move and the Collision stays at the place it originally landed. Once I click in the place it landed, the sprite moves back. It is currently in 'Rigid' mode.
Here's the gif:https://gyazo.com/77eb831c1cde39fb304927e07a50ff55
Here's the code:
extends RigidBody2D
# Variables that make it work
onready var spawner = get_node("/root/Scene/Player/Spawner")
onready var canDrag = false
# Stats
var massOutput = get_mass()
var weightOutput = get_weight()
func _ready():
pass
func _physics_process(delta):
#var canGrab = mouse_checker_node.is_free
if (Input.is_action_pressed("ui_grabItem") && canDrag == true):
var mousePos = get_global_mouse_position()
self.set_position(mousePos)
elif (Input.is_action_just_released("ui_grabItem")):
canDrag = false
func _on_Item_mouse_entered():
canDrag = true
#func _on_Item_mouse_exited():
# canDrag = false