Unity Health and Damage System - Combat Tutorial (VRoid)

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ •

  • @ReForgeMode
    @ReForgeMode  2 роки тому +9

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

    • @nikson12gg
      @nikson12gg 11 місяців тому

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

    • @ReForgeMode
      @ReForgeMode  11 місяців тому

      @@nikson12gg Yes, I did create a follow up to this video here: ua-cam.com/video/6MYmzIz7rE4/v-deo.html

    • @nikson12gg
      @nikson12gg 11 місяців тому +1

      @@ReForgeMode Thanks

  • @Tonedriver
    @Tonedriver 6 місяців тому +2

    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  6 місяців тому

      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! 😄😄

  • @JonJamesGordon
    @JonJamesGordon 2 роки тому +9

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

    • @ReForgeMode
      @ReForgeMode  2 роки тому

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

  • @marvinsteven3874
    @marvinsteven3874 2 роки тому +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  2 роки тому +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 😄😄

  • @Nibgames
    @Nibgames 2 роки тому +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  2 роки тому

      Thank you! Glad I could help!

    • @Nibgames
      @Nibgames 2 роки тому

      @@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  2 роки тому +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 2 роки тому +1

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

    • @ReForgeMode
      @ReForgeMode  2 роки тому

      Glad I could help! 😄😄

  • @NowLedgeIO
    @NowLedgeIO 11 місяців тому +1

    bro thats a very well teached tutorial.

    • @ReForgeMode
      @ReForgeMode  11 місяців тому

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

  • @Elucidator18
    @Elucidator18 Рік тому +3

    Very simple and useful tutorial thank you

  • @ogbeast8875
    @ogbeast8875 Рік тому +5

    Cant select my enemy as a object

    • @ReForgeMode
      @ReForgeMode  Рік тому +1

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

  • @Andrxano
    @Andrxano Рік тому +1

    Underrated channel, you just got 1 sub bro!

  • @pappermcflapper5329
    @pappermcflapper5329 Рік тому +1

    no rushing 10/10

    • @ReForgeMode
      @ReForgeMode  Рік тому

      No rushing here! All in due time 😄😄

  • @SHUBHAMGUPTA-bc7qs
    @SHUBHAMGUPTA-bc7qs Рік тому +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  Рік тому

      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 Рік тому +1

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

  • @Rix4h.
    @Rix4h. 10 місяців тому +1

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

    • @ReForgeMode
      @ReForgeMode  10 місяців тому

      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.

  • @ryanchen106
    @ryanchen106 6 місяців тому

    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  6 місяців тому

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

  • @nekojin1164
    @nekojin1164 2 роки тому +7

    LESGOOOOOO

    • @ReForgeMode
      @ReForgeMode  2 роки тому +2

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

    • @anlozge1788
      @anlozge1788 2 роки тому +1

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

  • @shoopie
    @shoopie День тому

    What is the 'atm' thats used all over these scripts?

    • @ReForgeMode
      @ReForgeMode  15 годин тому

      It refers to AttributeManager. You can change that variable name if you'd like.

  • @fredqq2003
    @fredqq2003 Рік тому

    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  Рік тому +1

      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.

  • @melomaniax5321
    @melomaniax5321 11 місяців тому

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

    • @ReForgeMode
      @ReForgeMode  11 місяців тому

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

  • @Glados44
    @Glados44 Рік тому

    @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  Рік тому +1

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

  • @rahulvyas4020
    @rahulvyas4020 11 місяців тому

    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  11 місяців тому

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

  • @westkossuth
    @westkossuth 9 місяців тому

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

    • @ReForgeMode
      @ReForgeMode  9 місяців тому

      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 9 місяців тому

      ​@@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  9 місяців тому +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! 😄😄

  • @hamismad123
    @hamismad123 Рік тому +1

    Great tutorial although the "GetKeyDown" thing isnt working

    • @ReForgeMode
      @ReForgeMode  Рік тому

      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 Рік тому

      No I did everything in the video

    • @ReForgeMode
      @ReForgeMode  Рік тому

      @@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.

  • @VinayakHiremathKLCS
    @VinayakHiremathKLCS Рік тому

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

    • @ReForgeMode
      @ReForgeMode  Рік тому

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

  • @themop2890
    @themop2890 6 місяців тому

    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  6 місяців тому

      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 6 місяців тому +1

      @@ReForgeMode thank you I appreciate!

    • @ReForgeMode
      @ReForgeMode  6 місяців тому

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

  • @sebax06
    @sebax06 Рік тому

    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  Рік тому +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.

  • @dogukantombul1045
    @dogukantombul1045 Рік тому

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

    • @ReForgeMode
      @ReForgeMode  Рік тому

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

    • @dogukantombul1045
      @dogukantombul1045 Рік тому

      yes@@ReForgeMode

    • @ReForgeMode
      @ReForgeMode  Рік тому

      @@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.

  • @DIGGER1842
    @DIGGER1842 3 місяці тому

    why you used .TakeDamage? its not a existing word i dont understand

    • @ReForgeMode
      @ReForgeMode  3 місяці тому

      Feel free to replace the name with any other name you're most comfortable with. But be sure to make it consistent and readable as you keep developing your game.

  • @estebangeorgenunezmoran7992
    @estebangeorgenunezmoran7992 2 роки тому +1

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

    • @ReForgeMode
      @ReForgeMode  2 роки тому +2

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

    • @estebangeorgenunezmoran7992
      @estebangeorgenunezmoran7992 2 роки тому

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

  • @KittySimmer2001
    @KittySimmer2001 10 місяців тому

    do u think i could use this in vrchat

    • @ReForgeMode
      @ReForgeMode  10 місяців тому

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

    • @KittySimmer2001
      @KittySimmer2001 10 місяців тому

      ya but no it use udo sharp@@ReForgeMode

  • @zuzubazooka6303
    @zuzubazooka6303 Рік тому +1

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

    • @ReForgeMode
      @ReForgeMode  Рік тому

      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);
      }

  • @Drummerdave.10
    @Drummerdave.10 9 місяців тому

    script pls

    • @ReForgeMode
      @ReForgeMode  9 місяців тому

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

  • @ReverseRythms
    @ReverseRythms 10 місяців тому

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

    • @ReForgeMode
      @ReForgeMode  10 місяців тому

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