How To Create Projectiles and Hitboxes - Godot 4

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 มิ.ย. 2024
  • In this tutorial, we build a complete projectile system. We create a projectile object. program attack functionality for a player, and integrate the projectile with a composable hitbox system to damage enemies.
    Thank you for watching!
    Moonwalk: Resurgence tundrafeedandsupplyco.itch.io...
    Chapters:
    0:00 Introduction
    0:30 Creating Projectile object
    2:00 Programming Projectile
    3:35 Add "attack" input action to input map
    3:40 Adding "attack" functionality to player & instantiating projectiles
    7:48 Creating a composable hitbox to work with our Projectile object
    9:23 Programming Hitbox
    #gamedev #godot #godot4 #gdscript
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 9

  • @Petergams
    @Petergams 26 วันที่ผ่านมา

    Thanks heaps.

  • @TheBoEoSoT
    @TheBoEoSoT 29 วันที่ผ่านมา

    nice tutorial, I really like it.
    Also could you please it louder next time?

    • @TundraFeedandSupplyCo
      @TundraFeedandSupplyCo  28 วันที่ผ่านมา

      Thank you! Apologies for the audio being quiet! I used to be too loud and it looks like I over corrected, haha.

  • @12plus99
    @12plus99 27 วันที่ผ่านมา

    Thanks for the tutorial! I've run into issues with instantiating objects before and this helped me wrap my head around it more.
    I was wondering, would it be better to put the bullets movement inside _physics_process() , to avoid projectiles phasing through targets at lower frame rates and/or faster bullet speeds?

    • @TundraFeedandSupplyCo
      @TundraFeedandSupplyCo  26 วันที่ผ่านมา +1

      Thank you for watching! Yes, you absolutely could use _physics_process in place of _process. Good idea!

  • @alexxander7289
    @alexxander7289 29 วันที่ผ่านมา

    TYVM !!! I liked all of this tutorial. I really liked it when you manually hooked up the hitbox signal.
    Was wondering how one could add a ammo clip of x projectile(s) capacity ?
    I could make an export variable of a several packed scenes for each projectile.
    And then remove the packed scenes. But Then I would have to manually add the packed scenes again, so the player could reload.
    Is this the path one would take to create the "ammo clip" capacity ?

    • @TundraFeedandSupplyCo
      @TundraFeedandSupplyCo  28 วันที่ผ่านมา

      Hi @alexxander7289! There are a bunch of different ways to do this. Pseudo coding an idea for how to implement this, I would likely:
      Create a "capacity" variable:
      @export var capacity = 5
      I would then create a variable to track how many shots the player has taken:
      var shotsRemaining = capacity
      Then a reloading variable:
      var reloading = false
      Inside our if(Input.is_action_just_pressed("attack") condition, we would need to decrement the shotsRemaining every time the player shot, potentially as the last step of the if statement as its placement will change the behavior:
      shotsRemaining -= 1
      I would wrap all the logic for creating a projectile in an if statement checking if shotsRemaining >= 0
      I would also add an if statement checking for shotsRemaining and starting a "reload" timer if applicable:
      if((shotsRemaining < 1) && (reloading == false):
      reloading = true
      $ReloadTimer.start()
      ReloadTimer would just be a Timer node attached to the player.
      In our ReloadTimer.timeout function in the player script, I would then reset shotsRemaining and reloading:
      reloading = false
      shotRemaining = capacity
      Let me know if that helps!

  • @Getupsitdown
    @Getupsitdown 29 วันที่ผ่านมา

    Isn’t the point of the collision shape 2d to act as a hit box? Did you need to act again

    • @TundraFeedandSupplyCo
      @TundraFeedandSupplyCo  28 วันที่ผ่านมา

      The CollisionShape2D node allows us to define the boundaries of a node, however it does not give us access to the same signals that are available on the Area2D node. Giving the Area2D a collision shape allows us to build on the functionality of the Area2D node with whatever boundaries we define with the CollisionShape2D node.
      The initial CollisionShape2D node assigned to the enemy and the player are used in this instance to stop the player and enemy from moving through each other. While those same collisions shapes could be used as a hitbox of sorts (though a CharacterBody2D needs a CollisionsShape2D and an Area2D needs also needs ones and I don't believe they can share child CollisionsShape2D nodes), there are instances where you may not want the sprite of an object to exactly match the hitbox.
      This also separates our behaviors into distinct, reusable components, following the "S" of SOLID principals (the Single-Responsibility principal). The hitbox node could be placed on any node, and immediately give hitbox related functionality.