How To Code Player Health & Fall Damage In Godot 4

Поделиться
HTML-код
  • Опубликовано: 30 янв 2025

Комментарии • 54

  • @Chamomileable
    @Chamomileable Год назад +3

    As someone switching to Godot from Unity, I can't tell you how much your tutorials have helped me acclimate myself Nagi. Really look forward to seeing more from you. Thanks a bunch for the education.

  • @TheBreadPirate
    @TheBreadPirate Год назад +3

    I just started learning programing this week, so I am horribly inept at the moment. But these guides seem really helpful so I'm going to try following them while learning code from an online class I'm taking!

    • @NagiDev
      @NagiDev  Год назад +1

      Oh my god, The Bread Pirate! I watch all your Zelda videos!

    • @TheBreadPirate
      @TheBreadPirate Год назад +2

      CAP! No freaking way.
      I was ticked off by Aonuma's latest interview when he said, "Why do you want to go back to a type of game where you're more limited," even though I love the old Zelda games. So I decided I need to learn game design to make my dream game myself. That's why I stumbled on your video. 😄
      But, of course, after studying game design for a few days I realized my dream game is way too ambitious for me. So for now I'm making Tic-Tac-Toe and PONG in Godot. But one day I'll do it.
      @@NagiDev

    • @AeroZone
      @AeroZone Год назад +2

      @@NagiDev this is your opportunity bro you can help him

    • @NagiDev
      @NagiDev  Год назад +2

      Yeah, please feel free to contact me over Discord I'd love to help you make a good Zelda game with actual dungeons. I have a tiny bit of experience recreating a BoTW clone.

  • @miguelvargas6758
    @miguelvargas6758 Год назад +2

    I also love your "game juice" segments!

  • @bariscanbilgin
    @bariscanbilgin Год назад +5

    Nagi this was a really great video thank you very much 🍀

  • @AdamNakonieczny
    @AdamNakonieczny Год назад +2

    I love the yellow logo version you used on walls and floors. in this color Godot looks dope! Thanks for the tutorial!

  • @jordan4longshaw
    @jordan4longshaw 5 месяцев назад +1

    Quality. Content. Helping me move to Godot, one tutorial at a time. Thanking you :)

  • @ParadoxTheBox
    @ParadoxTheBox 5 месяцев назад +2

    I can't thank you enough for these tutorials, you've kind of become my go-to when I hit a roadblock while making things. I really appreciate how modular your work is, and you describe it in a way that I can apply to my own project, even if it isn't a standard FPS.
    The autoloaded gamestate script is way more simple than preloading an entire other scene and somehow managing player data between them (for a turn based battle arena), which I was preparing to do earlier.
    Looking forward to seeing whats next! :)

  • @pascalcasier959
    @pascalcasier959 4 месяца назад +1

    simple and effective, very impressive. Thank you very much, that helped me a lot.

  • @saeedserwan
    @saeedserwan Год назад +2

    I love your videos man, thanks for the upload!

  • @NeroTofuu
    @NeroTofuu 11 месяцев назад +1

    tutorial was actually helpful AND entertaining. W job frfr

  • @GeneralChrisGaming
    @GeneralChrisGaming 4 месяца назад +4

    At the line *if diff > fall_damage_threshold*
    Ive added a *and is_on_floor():*
    To prevent player/character from takung damage if they have mutiple jump or anything thst changes their velocity in the air.

  • @miguelvargas6758
    @miguelvargas6758 Год назад +2

    great video!! learned a lot!

  • @TheRealKaiProton
    @TheRealKaiProton 2 месяца назад +1

    Another good video.

  • @ruumroom.
    @ruumroom. Год назад +1

    W TUTORIAL AS USUAL

  • @lord_razur
    @lord_razur Год назад +2

    For some reason adding the check shown here to make sure the player's falling velocity is negative didn't work for me, however I was able to make it work by changing the block to the following instead. I don't believe I can properly depict an indent here so (indent>) is standing in for one.
    var diff = velocity.y - old_vel
    if old_vel < 0 && diff > fall_damage_threshold
    (indent>) hurt()
    old_vel = velocity.y

  • @traumwelt1975
    @traumwelt1975 8 месяцев назад +1

    you lost me at the scene switcher things...HOWEVER i want to give you a huge thanks i have now an health bar !!! ^^ Also the previous tutorial was pure gold ! Thanks a lot !!

    • @NagiDev
      @NagiDev  8 месяцев назад

      If your game is going to have multiple playable scenes and you need to have the same amount of health in each level, you might want to come back and take a look at the scene switcher section.
      But yeah, I'm glad you like my tutorials!

    • @traumwelt1975
      @traumwelt1975 8 месяцев назад +1

      @@NagiDev yeah will try, but i don't know why , each time i try to listen to a signal i might do something wrong because it fails, nothing happens... Also would you be able to create a character switcher ? a press of a button that allows the player to changer player during game ? i need that for my project :$ Anyway, thanks a lot for all your hard work , the pleasing videos , and the fun parts too... I really love your channel ^^

  • @BobLobster-fo9zw
    @BobLobster-fo9zw Год назад +2

    Quick Question: in the getHealth function, you check for a key but that key is seemingly never defined. Is it part of a lockout to check if a script is allowed to access that data or does it have some other point?

    • @NagiDev
      @NagiDev  Год назад +1

      I did create the "health" key within the gamestate script. The function getHealth takes a key parameter which in this example stores the value "health". This means that the function is actually checking if the state has the key "health". So the getValue function can fetch a value as long as it is defined in the state. While the setValue function sets the value of a key regardless of the key being defined or not, since, it'll automatically define it if it isn't. So there isn't essentially any lockout, its just to avoid crashes in case some node tried to read a key that isn't present in the state. Hope it answers your question!

    • @BobLobster-fo9zw
      @BobLobster-fo9zw Год назад

      Oh thanks, I must ahve missed you creating it.

  • @zammey
    @zammey Год назад +3

    Hi Nagi! I am a valorant content creator who doesn't know all that much about game design but I had a brilliant idea for a video and was wondering if you would be willing to help me out with it?

    • @NagiDev
      @NagiDev  Год назад

      Sure thing! Hit me up over Discord @ nagidev

    • @zammey
      @zammey Год назад

      sent the friend request@@NagiDev

  • @DaPOPs
    @DaPOPs Год назад +1

    Wow! estuve buscando esto por un tiempo

  • @majosegomeztaberner7299
    @majosegomeztaberner7299 9 месяцев назад +1

    Hello Nagi! I know you have made a tutorial to make an interaction system in Godot 3, but could you make a new one in Godot 4? The code doesn't work for me even after copying and pasting it.

  • @GeneralChrisGaming
    @GeneralChrisGaming 4 месяца назад

    So after a bumch of back and forth it seems your good practice code freezes when i take damage but the bad practice code works fine. I have 0 idea how or way unless u changed something off screen

    • @NagiDev
      @NagiDev  4 месяца назад +1

      Does it just freeze the player or does Godot throw an error message as well?

    • @GeneralChrisGaming
      @GeneralChrisGaming 4 месяца назад +1

      ​​@@NagiDevon mobile u cant see error message on a crash as u have to close the whole program something I hope they fix. After looking letter by letter I eventually saw I put state_value instead of set_value in the game state.gd that was a annoying 30 minute mistake, my bad!

  • @Dragon20C
    @Dragon20C 10 месяцев назад

    I am not sure how your if statement is working, because for me diff is a negative number so it will not ever pass 20, strange might be the difference between player controllers.

    • @NagiDev
      @NagiDev  10 месяцев назад

      On the frame the player hits the floor,
      velocity.y = 0 and old_vel = some negative value (say -1)
      so, as per the code,
      diff = velocity.y - old_vel
      diff = 0 - (-1)
      diff = 1
      At least according to the code in the video, your diff value should be positive.

    • @Dragon20C
      @Dragon20C 10 месяцев назад +1

      @@NagiDevooh that makes sense, it probably doesnt help I am using a state machine but I know how to fix it, thanks for the reply!

  • @jordan4longshaw
    @jordan4longshaw 5 месяцев назад

    Hey, having trouble doing percentage based fall damage. Do you know how I'd go about it?
    Cause currently I do fall damage how you do, but if I increase my player characters HP to 1000, the fall damage from a height that dealt like 20 hit points before, still does 20 hit points.

    • @NagiDev
      @NagiDev  5 месяцев назад

      The fall damage is dealt by a fixed amount, so changing the health would not affect the fall damage. The easiest solution I can think of is to add a multiplier variable that you multiply with the calculated fall damage. On top of that, you can make that variable an @export variable so you can modify it from the inspector.

    • @jordan4longshaw
      @jordan4longshaw 5 месяцев назад

      ​@@NagiDev Yeees, fixed depending on the height the player falls from.
      Interesting idea, not encountered multiplier variables yet. I searched them up & got links for "Godot multiplayer" instead of "Godot multiplier variables", damn search engines aha
      How might one create & add a multiplier variable?👀

    • @jordan4longshaw
      @jordan4longshaw 4 месяца назад

      @@NagiDev Indeed, fixed depending on the height the player fell from. Interesting, not yet heard of "multiplier variables" before... how might I go about them? When I search for them I just get stuff about multiplayer lol

    • @NagiDev
      @NagiDev  4 месяца назад +1

      A multiplier variable is just an ordinary export variable with the value set to a number, and in the fall damage calculation code we wrote, you just multiply it to the final value.
      You can check out the link to the code in the description. It has the fall damage multiplier code included.

    • @jordan4longshaw
      @jordan4longshaw 4 месяца назад +1

      @@NagiDev So it is, and so it do. Big thanks from me! Fall damage multiplier implemented, love it when event he small things get working. Thanks man :)

  • @clashofclans9783
    @clashofclans9783 Год назад

    plz how to make head bone look at player

    • @NagiDev
      @NagiDev  Год назад +1

      I'm not sure but I think the look_at() function would do the trick. The villager in my old fps video didn't use bones, so you might have to use some other technique.

    • @clashofclans9783
      @clashofclans9783 Год назад +1

      @@NagiDev I thought your villager had a bone, so I thought you had a solution. I try look_at() function and I tell you and thank you♥️

    • @clashofclans9783
      @clashofclans9783 Год назад

      ​@@NagiDevcode doesn't work😢

  • @ruumroom.
    @ruumroom. Год назад +1

    NICEEE

  • @ProbablyM_S
    @ProbablyM_S Год назад

    you didn't explain Tween :( but as always great tutorial they are fun and informative (accept the tween part)😒

    • @BobLobster-fo9zw
      @BobLobster-fo9zw Год назад +3

      A tween is just a way of "animating" values with code. So instead of setting a value from i.e. 1 to 5 instantaneous, you have it count up from 1 to 5 over a certain amount of time.
      So the parameters you input are: Thr object you want the tween function to work on, the property of that object you want to tween, the final value you want it to reach and the time in seconds it should take.

    • @NagiDev
      @NagiDev  Год назад +1

      Yea I only gave a short overview. I'll go into further depth in a future video for sure.

  • @AeroZone
    @AeroZone Год назад +1

    At the moment i dont understand much 😅