Unity Health and Damage System - Combat Tutorial (VRoid)

Sdílet
Vložit
  • čas přidán 22. 08. 2024
  • In this tutorial, you'll learn how to create health and damage system in Unity and VRoid Studio. This is part one of the new melee combat tutorial with VRoid characters. I'm very excited for this series!
    Part Two Combat Tutorial: • The Complete Damage Po...
    In this tutorial, you'll learn:
    - How to create a health and attack attribute
    - How to handle incoming damage and dealing damage to other units
    - This tutorial is intended for absolute beginners in Unity programming
    - We'll go over some basic concepts in programming
    If this video helps you, don't forget to like and subscribe!
    Download the project here:
    github.com/ReF...
    SOCIAL MEDIA:
    Patreon: / reforgemode
    Ko-Fi: ko-fi.com/refo...
    Twitter: / feyhunt
    Discord: / discord
    GitHub: github.com/ReF...
    #VRoid #Unity #Tutorial #VRoidStudio

Komentáře • 79

  • @ReForgeMode
    @ReForgeMode  Před 2 lety +9

    If you have any questions, feel free to ask it in the comments below!

    • @nikson12gg
      @nikson12gg Před 7 měsíci

      Is there any video, about activating damage script when damage animation is 70-90% done or something?

    • @ReForgeMode
      @ReForgeMode  Před 7 měsíci

      @@nikson12gg Yes, I did create a follow up to this video here: czcams.com/video/6MYmzIz7rE4/video.html

    • @nikson12gg
      @nikson12gg Před 7 měsíci +1

      @@ReForgeMode Thanks

  • @marvinsteven3874
    @marvinsteven3874 Před 2 lety +5

    Glad to see, that you are better and back doing these videos.
    You're pretty much the only one who does Vroid and Unity videos.

    • @ReForgeMode
      @ReForgeMode  Před 2 lety +1

      Thank you! Oh, surely not! I know some people who do it better than I do...
      And I'm planning to catch up to them soon. I should be able to post more regularly now that my schedule is mostly clear 😄😄

  • @JonJamesGordon
    @JonJamesGordon Před 2 lety +9

    Love the pacing! Quick to the point while still providing lots of extra information. Looking forward to more!

    • @ReForgeMode
      @ReForgeMode  Před 2 lety

      Thank you! Pacing is one of many issues I have with these videos. I will try to make it even snappier next time!

  • @Nibgames
    @Nibgames Před rokem +5

    So glad that you went over all the basics! Most tutorials skip this sort of information but as a new developer this is very useful. I've subscribed :)

    • @ReForgeMode
      @ReForgeMode  Před rokem

      Thank you! Glad I could help!

    • @Nibgames
      @Nibgames Před rokem

      @@ReForgeMode I have yet to see the other tutorial videos, but would a good alternative to this be to make separate attributes for the player and the enemies? So that you would have PlayerHP, PlayerAttack and EnemyHP, EnemyAttack for example. To me this sounds like it may be easier to work with, but I'm new to developing so I might be missing something. Curious what you think :)
      Edit: I should probably add that I also wrote a simple Defense integer that substracts the Attack damage dealt by x Def amount

    • @ReForgeMode
      @ReForgeMode  Před rokem +1

      That is the beauty and major cause of headache in programming. There are so many ways to implement an idea, you have to choose which one is appropriate.
      Separating player and enemy script is an option. But it has several downside:
      - Harder to maintain. If in the future, you decided to add a new attributes, say Magic Defense, you will have to modify both of the scripts manually. If you accidentally name the attributes differently, like attack and atack in these two scripts, it will not be fun.
      - What if: enemy attack each other? Let's say you implemented a mechanic where enemies can now attack each other. Maybe it's as simple as friendly fire between enemies, or maybe the enemies have multiple factions that can attack each other. How do you code enemies damaging each other? If you separate the script for enemies and player, you will have to check if the thing attacked is either a player or an enemy, and then use the appropriate GetComponent function, for every enemy damaging abilities.
      - What if: multiplayer? Maybe it's a co-op with friendly fire, or a PvP content. How do you code player damaging other players? Same as before, you will need to check if the player damages an enemy or a fellow player in every single hit.
      This won't be an issue if you make the attributes universal to the player and enemy. The attacker shouldn't need to care what it hits.
      But there is a middle ground. Later on, you might want to implement something called Interface or Inheritance, so you can have a variation of the same script, but you don't need if statements to get the right GetComponent function. This basically solves all of the problems above.
      And... I'm making that video right now!
      Hopefully that answers your question!

    • @Nibgames
      @Nibgames Před rokem +1

      @@ReForgeMode Ohh thank you so much for the detailed reply and insight, that makes sense! Really helps

    • @ReForgeMode
      @ReForgeMode  Před rokem

      Glad I could help! 😄😄

  • @Tonedriver
    @Tonedriver Před 2 měsíci +1

    Love this, really opens things up for me, among others’ tutorials.
    Eventually I want to include “slow” effect on damage, “damage over time” effect on damage, audio events on damage, and simple indication visuals/ animation events on damage.
    But what I want to learn first is how to make either, my Heads Up Display’s crosshair, or my player camera and enemy’s raycast create damage hit.

    • @ReForgeMode
      @ReForgeMode  Před 2 měsíci

      Glad I can help you!
      Crosshair is very easy. Just put an image in a Canvas and place it at the center of your screen. You're already on the right track to raycast the enemy and deal damage, just use Camera.ScreenToWorld and then Physics.Raycast.
      Excited to see what you'll make next! 😄😄

  • @NowLedgeIO
    @NowLedgeIO Před 8 měsíci +1

    bro thats a very well teached tutorial.

    • @ReForgeMode
      @ReForgeMode  Před 8 měsíci

      Oh, thank you! I am also working on Health Bar UI next. Could be a while to finish though hehe.

  • @Elucidator18
    @Elucidator18 Před rokem +3

    Very simple and useful tutorial thank you

  • @Andrxano
    @Andrxano Před 11 měsíci +1

    Underrated channel, you just got 1 sub bro!

  • @pappermcflapper5329
    @pappermcflapper5329 Před 10 měsíci +1

    no rushing 10/10

    • @ReForgeMode
      @ReForgeMode  Před 10 měsíci

      No rushing here! All in due time 😄😄

  • @ogbeast8875
    @ogbeast8875 Před 11 měsíci +4

    Cant select my enemy as a object

    • @ReForgeMode
      @ReForgeMode  Před 11 měsíci +1

      Could you elaborate on this? You can select your enemy object by clicking on their name in the Hierarchy Window.

  • @nekojin1164
    @nekojin1164 Před 2 lety +7

    LESGOOOOOO

    • @ReForgeMode
      @ReForgeMode  Před 2 lety +2

      Yes! I'm so excited. Never made a tutorial series before. I hope I won't disappoint!

    • @anlozge1788
      @anlozge1788 Před rokem +1

      @@ReForgeMode Very informational video. Thanks for this quality content. Really appreciated!

  • @SHUBHAMGUPTA-bc7qs
    @SHUBHAMGUPTA-bc7qs Před rokem +2

    Great Tutorial, I just had one question.
    So I have a day night cycle animation in my project, and I want it so that my damage is different at day. How can I do this?

    • @ReForgeMode
      @ReForgeMode  Před rokem

      Interesting. Are you making a vampire game perhaps?
      It'a quite simple. Create a float variable for day/night cycle, then when dealing damage, check if the time of day is day or night.

    • @shubhamgupta9601
      @shubhamgupta9601 Před rokem +1

      @@ReForgeMode Damn dude your guess was spot on.
      I'll try your idea, and let you know.
      Thanks a ton

  • @ryanchen106
    @ryanchen106 Před 3 měsíci

    How would I implement this to a first person shooting game, I want my projectile that I’m shooting to deal damage. And I want the monster to damage me when they collide with my player

    • @ReForgeMode
      @ReForgeMode  Před 3 měsíci

      Then you just need to call the damage function when the enemy collides with your character collider with OnColliderEnter. Same thing for bullets.

  • @Glados44
    @Glados44 Před rokem

    @Reforge Mode you make a great video. I have a question.
    You use the damage tester with a key bind f11 f12 but this only makes effect if i use this keys. What about if i want to make damage with a bullet object.
    I was thinking oncollider hit to activate the attribute manager functions?
    If you can expand the combat tutorial that would be awesome. But anyways it really help me this video. Thank you

    • @ReForgeMode
      @ReForgeMode  Před rokem +1

      Thank you! You can use OnCollider other.GetComponent() to get the reference to your health script and call the damage function.

  • @Rix4h.
    @Rix4h. Před 7 měsíci +1

    i cant add DamageTester script to DamageTester object because script class cannot be found

    • @ReForgeMode
      @ReForgeMode  Před 7 měsíci

      Hmmm... It's usually an error because of the class name is different than the script name or a typo. Try it and see if it works.

  • @themop2890
    @themop2890 Před 3 měsíci

    Im newer to learning unity how would I have it reset player position/destroy enemy when the health hits 0 I’m using the 2021 unity

    • @ReForgeMode
      @ReForgeMode  Před 3 měsíci

      Then I recommend browsing the official Unity Learn website to get the basics.
      The short answer is to use transform.position to the player and using Destroy(gameobject) for the enemy.

    • @themop2890
      @themop2890 Před 3 měsíci +1

      @@ReForgeMode thank you I appreciate!

    • @ReForgeMode
      @ReForgeMode  Před 3 měsíci

      @@themop2890 No problem! Excited to see what you'll make in the future!

  • @fredqq2003
    @fredqq2003 Před rokem

    I am always tortured by making fighting collision. If we want to use fists to attack enermies, it seems not appropriate to use box collider or any other collider, because they will detect other things before detecting enermies. Have you used boxcast before? I wonder if I can use BoxCast to serve as collider

    • @ReForgeMode
      @ReForgeMode  Před rokem

      That's why you should specify which layerMask you're targeting in BoxCast. LayerMask allows you to only interract with specific things, like enemy colliders.
      Of course, you need to first separate each object in your game into separate layers, like terrains, enemies, interactibles, etc.

  • @rahulvyas4020
    @rahulvyas4020 Před 8 měsíci

    I have one where the enemy is a dragon and I have a sword, as combat animation and I have a combo system, How do I do basic health and damage, like Heath is 500 and damage is 10 per strike/combo, easily, I've seen multiple tutorials and everyone's is so different I am confused.

    • @ReForgeMode
      @ReForgeMode  Před 8 měsíci

      I gotcha fam. Basically, you need to create a collision box to trigger the damage. I made a tutorial for it right here:
      czcams.com/video/6MYmzIz7rE4/video.htmlsi=4n6X6jCvNlLQk0DI

  • @sebax06
    @sebax06 Před 8 měsíci

    I don't know why, but every time I press the button I select, the objects take much more damage than I assigned to them (I put 5 damage on the enemy but the ally receives more than 200 damage xD).

    • @ReForgeMode
      @ReForgeMode  Před 8 měsíci +1

      I think there may be a problem with multiple triggers. Make sure you're using Input.GetKeyDOWN instead of Input.GetKey. GetKeyDown will only register one button press, while GetKey will trigger every frame as long as the button is pressed. Let me know if this helps!
      Also, if the enemy and player doesn't appear, it's because you should open the Scene in the Project Window first. Double click to open it. By default, Unity always loads in default empty scene.

  • @estebangeorgenunezmoran7992

    It would be interesting if you explain a quest system like genshin impact.

    • @ReForgeMode
      @ReForgeMode  Před rokem +2

      We'll get there eventually, but we need to finish the combat system first since it's highly requested.

    • @estebangeorgenunezmoran7992
      @estebangeorgenunezmoran7992 Před rokem

      @@ReForgeMode That'll also be great haha thanks!

  • @melomaniax5321
    @melomaniax5321 Před 8 měsíci

    I did exactly as you said but the code error shows AttributesManager error (type or namespace not found)

    • @ReForgeMode
      @ReForgeMode  Před 8 měsíci

      The most likely cause is a typo somewhere. Make sure to name your scripts and class name carefully. Lowercase or uppercase letters matter.

  • @hamismad123
    @hamismad123 Před rokem +1

    Great tutorial although the "GetKeyDown" thing isnt working

    • @ReForgeMode
      @ReForgeMode  Před rokem

      The syntax is Input.GetKeyDown(KeyCode.F12). Have you double checked you didn't mistype the keys? Or perhaps press the wrong key?

    • @hamismad123
      @hamismad123 Před rokem

      No I did everything in the video

    • @ReForgeMode
      @ReForgeMode  Před rokem

      @@hamismad123 There are many reasons why the key doesn't get registered:
      - Make sure you added the script as a component in the inspector and it's not disabled.
      - Make sure that GetKey exist in the Update function
      ...and many more.
      I need more details to help you out.

  • @westkossuth
    @westkossuth Před 6 měsíci

    This works great for 1v1 combat, but how is this sysstem supposed to be implemented when there are multiple enemies present?

    • @ReForgeMode
      @ReForgeMode  Před 6 měsíci

      Well, with every collision from the player's weapon, it will deal damage to all enemies.
      I don't get how you can say it's great only for 1v1. It's actually the opposite, good for multiple enemies, not so good for a 1v1 fight like in some fighting games.

    • @westkossuth
      @westkossuth Před 6 měsíci

      ​@@ReForgeMode Maybe I'm confused, wouldn't you have to then hook up the attribute manager for each individual enemy present in the scene?

    • @ReForgeMode
      @ReForgeMode  Před 6 měsíci +1

      @@westkossuth No, that's not how it works. Let me explain.
      So the way you program this is that when the OnHit collision happens, it will immediately try to get the enemy's attribute component and call in DealDamage function to it.
      It doesn't matter how many enemies you hit. As long as there is contact with the collider, their function will be called.
      The only thing you need to do to set up the enemy is to make sure they have that Attribute component.
      Later on, you can also incorporate different types of Attributes component if there are some enemies that takes damage differently, like with Defense or special mechanics.
      Let me know if you need more help! 😄😄

  • @VinayakHiremathKLCS
    @VinayakHiremathKLCS Před rokem

    when we press F12 key the health reduces. what to write in if condition if we want to crick button from joystick??

    • @ReForgeMode
      @ReForgeMode  Před rokem

      It depends what joystick you use and what platform your game is running in. i recommend checking out Input System in Unity.

  • @zuzubazooka6303
    @zuzubazooka6303 Před rokem +1

    really good tutorial! Sadly nothing happens when health = 0. and why doesnt this work:
    if (health = 0)
    {
    destroy (gameObject, life);
    }?

    • @ReForgeMode
      @ReForgeMode  Před rokem

      Thanks! Destroy(gameObject, life) means that you're trying to destroy this specific gameObject with a time delay of "life" seconds.
      It works, but there is a massive delay. What are you trying to do there?
      If you want to have an object with multiple life count, instead add this inside the first if:
      If(life > 0)
      {
      life--;
      health = maxHealth;
      }
      else
      {
      Destroy(gameObject);
      }

  • @dogukantombul1045
    @dogukantombul1045 Před 9 měsíci

    when I start and restart the game my health wont restart it just keeps the previous value

    • @ReForgeMode
      @ReForgeMode  Před 9 měsíci

      Hmmm... that is weird. Is this the health value in the inspector?

    • @dogukantombul1045
      @dogukantombul1045 Před 9 měsíci

      yes@@ReForgeMode

    • @ReForgeMode
      @ReForgeMode  Před 9 měsíci

      @@dogukantombul1045 Okay, is there any function in your script that sets the health manually? Something like health = 2?
      Are you using ScriptableObject to store the value?
      Without looking at your script, I can't tell what is wrong. You can join our discord server and share your script right there. Link is in the description.

  • @KittySimmer2001
    @KittySimmer2001 Před 7 měsíci

    do u think i could use this in vrchat

    • @ReForgeMode
      @ReForgeMode  Před 7 měsíci

      I'm not sure. This is a Unity tutorial. Is VRChat based on Unity?

    • @KittySimmer2001
      @KittySimmer2001 Před 7 měsíci

      ya but no it use udo sharp@@ReForgeMode

  • @Drummerdave.10
    @Drummerdave.10 Před 5 měsíci

    script pls

    • @ReForgeMode
      @ReForgeMode  Před 5 měsíci

      It's in the description. Just download the Github project.

  • @ReverseRythms
    @ReverseRythms Před 7 měsíci

    i need your help in my game, how can i contact you?

    • @ReForgeMode
      @ReForgeMode  Před 7 měsíci

      Feel free to contact me through my email at reforgemode@gmail.com or PM me on Discord feyhunt