How to pickup kinematic items with 2d platformer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mrpaolosarino

I want to create a gun item where if I press ‘E’ then the gun will position itself to my player’s hand. I already set it up. Etc. But the problem is once I pressed the E then the gun will disappear. I try to print the gun location and it says (0,0). Any experts out there?

var Picked = false
func Picked():
if Picked == false:
var bodies = $Area2D.get_colliding_areas()
for b in bodies:
if b.name == “Player_pickup”:
self.position = get_node(“/Player/Transform2D”).position

I tried Z-index, collision layer but still, nothing has changed

:bust_in_silhouette: Reply From: IHate

get_node("/Player/Transform2D") should be get_node("Player/Transform2D")
you didn’t get an error with that in? is the transform position (0,0)? maybe you are moving the position of the sprite instead of the whole player node. If you are not moving the gun to the Player Node tree use global_position instead of position, because position is local so Transform2D will take its position based on the Player node and the Gun will take its position based on the top left corner of the scene or its parent.