How to make guns and pick them up

Godot Version

4.2.1

Question

I’m new to Godot and I was wondering how I could make a pickup system for guns and make guns actually shoot for my 2d game. Any help or advice would be much appreciated, and i am using gdscript


It’s all slight-of-hand and mostly revolves around area/body collisions.

When your player collision shape collides with a weapon collision shape on the floor, a signal is produced called body_entered. This will provide you the area or physics body node reference.

So the players physics body will get a collision signal. You will need to check if it is a weapon. If it is then you remove the child from the scene and add it to the player “hands” tree node.

If you want to look at a weapon and use an input to pick it up. Godot provides raycasting class to sense the object your camera is pointing at.

Then similar to before l, the ray will collide with an object and determine if it is a weapon. If it is then you should prompt the player that an input option is available to pickup the weapon. And if the user presses the input you do the exact same steps as floor pickup. Remove the weapon from the scene tree and add it on the users hand node.