First you will need to decide what type of node you will use for the bullets.
Mainly you will choose from RayCast2D
or RigidBody2D
(or KinematicBody2D
), they both have their advantages and disadvantages but basically:
For bullets that are very fast (think realistic levels of bullet speed) i would use a RayCast2D
, this will be a "hitscan" bullet (This means the hit is registered where the raycast is colliding at the exact frame you shoot, there is nothing travelling)
For something like, lets say, a missile or a cannon shot, i would use RigidBody2D
this would be a "projectile" (This means it is a physical body "launched" from the weapon and it travels across the map in the physical space) IMPORTANT: if you use this method and the projectile travels too fast, it may pass through objects, since it will be in front of the object in one frame and then have passed it in the next frame, there will be no frame in which the projectile and the object overlap, and therefore no collision detected.
For a RayCast2D
, you would first create a raycast2D node as a child of the weapon (So it inherits its direction) and that's pretty much it (Besides setting up the length of the "Cast_to
" property, depending on how far you want the shot to travel)
With a RigidBody2D
it is a bit more tricky, you will have to create the projectile in a different scene and then create and instance of it when you shoot. After that you would apply_central_impulse
Keep trying, you will figure it out, try to start small to get the hang of it and dont forget to google the terms i used here. Good luck!