Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sygi |
I have a 3D node with an item (RigidBody3D) which a character (CharacterBody3D) can pick up and drop. When the item is picked up, it should follow the character around, until when it’s dropped. I’m trying to achieve it by having the objects stored in some global node, and parenting them to the character when picked up.
This is my pick up code:
@rpc("call_local")
func _pick_up(item_path):
var item = get_node(item_path)
item.sleeping = true
var original_global_position = item.global_position
item.get_parent().remove_child(item)
add_child(item)
item.set_owner(self)
item.global_position = original_global_position
item.collision_layer &= (2**32 - 1) - 1
item.sleeping = false
Unfortunately, setting the position this way, as opposed to using the forces directly, leads to physics issues. Initially I tried this without removing the collision layer with the player and without sleeping but this led to more frequent issues.
What is a canonical way to solve this problem, ie. reparenting a node without changing its position?