Grabbing then dropping object doesn't allow me to pick it up again

I am trying to make a simple grab and drop item system, where you right-click to pick up the item you are looking at, and press the same button again to drop it.

It only works for items marked with “grabable” group. It works perfectly the first time I pick up an item, but when I drop it, I can;t pick it up again and the raycast prints that it is detecting the group, not the item I’m looking at.

if Input.is_action_just_pressed("interact_right"):
		if rightHandObject:
			rightHandObject.reparent($"../..")
			rightHandObject.add_to_group("grabable")
			rightHandObject = null
		else:
			var object = camera_target.get_collider()
			print(object)
			if object is RigidBody3D and object.is_in_group("grabable"):
				object.remove_from_group("grabable")
				object.reparent(carry_object_right_hand)
				object.global_position = carry_object_right_hand.global_position
				object.global_rotation = carry_object_right_hand.global_rotation
				object.collision_layer = 2
				rightHandObject = object

Note: I am brand new to Godot, I have experience with other engines/languages but I am just starting to learn Godot :slight_smile:

You’re changing the collision layer of the object when you pick it up, but you don’t change it back when you put it down. Then probably your ray can’t detect it anymore.

1 Like