Announcement

Collapse
No announcement yet.

floats vs integers for health system

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    floats vs integers for health system

    I've been following a tutorial on how to make a health system which uses integers, and came pretty far in it. I have health, can simulate damage, and have setup a health pickup. In trying to create a regen system though, I've found that I seemingly need to use floats, particularly when it comes to delta seconds and world time. I'm not sure how to proceed as I can't seem to find a health regen guide that doesn't use floats. Are floats supposed to be used for this sort of system, and is it possible to convert the existing setup without issues?

    Caldera Entertainment | Twitter | ArtStation

    #2
    Originally posted by SE_JonF View Post
    I've been following a tutorial on how to make a health system which uses integers, and came pretty far in it. I have health, can simulate damage, and have setup a health pickup. In trying to create a regen system though, I've found that I seemingly need to use floats, particularly when it comes to delta seconds and world time. I'm not sure how to proceed as I can't seem to find a health regen guide that doesn't use floats. Are floats supposed to be used for this sort of system, and is it possible to convert the existing setup without issues?
    You dont have to use float at all.
    Floats give a bit more flexibility in every kind of calculation but it depends on what you want to achieve.
    Do you need the regeneration to be as precise as possible? ( = every frame) or just some health after a while?
    Single or multiplayer based?

    I love to use Timers for regeneration and for that you could also use integers.

    Comment


      #3
      You can create a system to repeatedly call a function to increase your health.

      * Create a function, I'd call it StartRegen;

      * Create a boolean bIsRegenerating?;

      * Inside your StartRegen function, make a branch to check if you bIsRegenerating is true. After that, increase your health by '1'. And after that, use the node "Set Timer by Function Name". The Function Name will be StartRegen and the time you decide.

      Following this logic, you can get close to an analog health regeneration (using int) depending on the time you set inside Set Timer by Function Name. It's a good way to control how much health you want the player to regen in a period of time. It has, too, condition to stop regenerating since you set the bIsRegenerating to false, it will not execute the loop again. You can add that it stops regenerating when the health is set to maximum value and it interrupts the call loop, too...

      Comment


        #4
        Floats are nice to have and use, but are not required for an operating health system. Depending on the type of regen system you have in mind, your mileage may vary.

        I personally put the regen system into a Function. I put all of the handling of the regeneration into the function, including the checks and balances of whether we have exceeded or even if we can regenerate. All of this is figured out before any regeneration is even done. I will leave it up to you on how you wish to accomplish this, and if you are following tutorials, it is really easy to adapt the system to Integers.

        When setting up all of the stats and stuff, put a Set Timer by Function and put the function name in. Turn on the Looping and give it a delay as you see fit, I personally use a variable so that it is unique to that instance of the blueprint. The nifty thing about that variable I just made, it is a Float variable. This is where you can implement the Float part of the tutorial if you deem it necessary.

        Comment


          #5
          Originally posted by Urm92 View Post
          You dont have to use float at all.
          Floats give a bit more flexibility in every kind of calculation but it depends on what you want to achieve.
          Do you need the regeneration to be as precise as possible? ( = every frame) or just some health after a while?
          Single or multiplayer based?

          I love to use Timers for regeneration and for that you could also use integers.
          Singleplayer for the moment, but possibly multi in the future. I'm trying to setup a system that regenerates health say 5 seconds after you've last taken damage. I was able to get the regeneration to work, but the delay value seems to repeat. (i.e. 5 seconds, +5 health, 5 seconds + 5 health). I tried the retriggerable but that doesn't seem to work at all.

          Originally posted by Gbr View Post
          You can create a system to repeatedly call a function to increase your health.

          * Create a function, I'd call it StartRegen;

          * Create a boolean bIsRegenerating?;

          * Inside your StartRegen function, make a branch to check if you bIsRegenerating is true. After that, increase your health by '1'. And after that, use the node "Set Timer by Function Name". The Function Name will be StartRegen and the time you decide.

          Following this logic, you can get close to an analog health regeneration (using int) depending on the time you set inside Set Timer by Function Name. It's a good way to control how much health you want the player to regen in a period of time. It has, too, condition to stop regenerating since you set the bIsRegenerating to false, it will not execute the loop again. You can add that it stops regenerating when the health is set to maximum value and it interrupts the call loop, too...
          I tried doing this, but I couldn't seem to get it to work. I should probably note I'm very new to blueprints.

          Originally posted by Yggdrasil View Post
          Floats are nice to have and use, but are not required for an operating health system. Depending on the type of regen system you have in mind, your mileage may vary.

          I personally put the regen system into a Function. I put all of the handling of the regeneration into the function, including the checks and balances of whether we have exceeded or even if we can regenerate. All of this is figured out before any regeneration is even done. I will leave it up to you on how you wish to accomplish this, and if you are following tutorials, it is really easy to adapt the system to Integers.

          When setting up all of the stats and stuff, put a Set Timer by Function and put the function name in. Turn on the Looping and give it a delay as you see fit, I personally use a variable so that it is unique to that instance of the blueprint. The nifty thing about that variable I just made, it is a Float variable. This is where you can implement the Float part of the tutorial if you deem it necessary.
          I'll give that a try. This stuff gets confusing pretty fast. I'm surprised there isn't a whole lot of coverage on how to setup extensive health systems (health, shields, regen, etc.).
          Last edited by SE_JonF; 05-31-2016, 11:22 AM.

          Caldera Entertainment | Twitter | ArtStation

          Comment


            #6
            There are a LOT of tutorials on setting up a health system. UE4 even comes with a version of it, themselves (don't recommend it at the moment). Your best bet would be to take a look at some of the YouTube Health Tutorials for UE4 and see what they do. I wish I could show you my setup right now, but this laptop seriously lacks power.

            Comment


              #7
              Originally posted by Yggdrasil View Post
              There are a LOT of tutorials on setting up a health system. UE4 even comes with a version of it, themselves (don't recommend it at the moment). Your best bet would be to take a look at some of the YouTube Health Tutorials for UE4 and see what they do. I wish I could show you my setup right now, but this laptop seriously lacks power.
              I've found many that have to deal with health systems yes, but I don't really see any covering the topic of regen. Those that do don't very well. I'm trying to get my health system which uses integers to regen after x time since taking damage.

              Caldera Entertainment | Twitter | ArtStation

              Comment


                #8
                You may want to consider some Sprint tutorials. They cover the exact concepts you are thinking of doing with health, except having to do with sprinting. Same concept, just a different condition to change.

                Comment


                  #9
                  Originally posted by Yggdrasil View Post
                  You may want to consider some Sprint tutorials. They cover the exact concepts you are thinking of doing with health, except having to do with sprinting. Same concept, just a different condition to change.
                  That's a good idea, I'll check that out.

                  Caldera Entertainment | Twitter | ArtStation

                  Comment


                    #10
                    Originally posted by Gbr View Post
                    You can create a system to repeatedly call a function to increase your health.

                    * Create a function, I'd call it StartRegen;

                    * Create a boolean bIsRegenerating?;

                    * Inside your StartRegen function, make a branch to check if you bIsRegenerating is true. After that, increase your health by '1'. And after that, use the node "Set Timer by Function Name". The Function Name will be StartRegen and the time you decide.

                    Following this logic, you can get close to an analog health regeneration (using int) depending on the time you set inside Set Timer by Function Name. It's a good way to control how much health you want the player to regen in a period of time. It has, too, condition to stop regenerating since you set the bIsRegenerating to false, it will not execute the loop again. You can add that it stops regenerating when the health is set to maximum value and it interrupts the call loop, too...
                    Here is what I created based off of your post. Not sure if this is what you meant, but it doesn't seem to be doing anything. My HP regenerates as soon as it is taken away. I also managed to convert all of the integers to floats.

                    Click image for larger version

Name:	BP.jpg
Views:	1
Size:	306.6 KB
ID:	1107452

                    Caldera Entertainment | Twitter | ArtStation

                    Comment


                      #11
                      Try something like in this picture:

                      Click image for larger version

Name:	unrelaex.png
Views:	1
Size:	97.3 KB
ID:	1107466

                      Here you can see the variable IntervaltoRegen. That variable will be important for you to set the regen rate. If you set this variable to 0.2, in 1 second, it will run the function 5 times, so it means your character will recover 5 health points. You can decrease the time to increase regen rate.

                      Let me know if this solution works for you

                      Comment


                        #12
                        Originally posted by Gbr View Post
                        Try something like in this picture:

                        [ATTACH=CONFIG]95605[/ATTACH]

                        Here you can see the variable IntervaltoRegen. That variable will be important for you to set the regen rate. If you set this variable to 0.2, in 1 second, it will run the function 5 times, so it means your character will recover 5 health points. You can decrease the time to increase regen rate.

                        Let me know if this solution works for you
                        Hey Gbr,

                        I gave your setup a go. It pretty much functioned like my other regen setups, except it exceeded max health. Clamping it, or using a modified setup like below fixed it but the regen rate is still immediate. I want it to have a delay before regenerating. The rate of regeneration in the setup is great, I want the quick regen, but I want it to happen x seconds after taking damage, that way the damage isn't constantly fighting a constant regen. Here's what I did based on your image:

                        Click image for larger version

Name:	BP.jpg
Views:	1
Size:	305.9 KB
ID:	1107477

                        Also, this is the tutorial I used to setup my health system if that may give you an idea of how it works.

                        I appreciate your help!

                        Caldera Entertainment | Twitter | ArtStation

                        Comment


                          #13
                          Originally posted by SE_JonF View Post
                          Hey Gbr,

                          I gave your setup a go. It pretty much functioned like my other regen setups, except it exceeded max health. Clamping it, or using a modified setup like below fixed it but the regen rate is still immediate. I want it to have a delay before regenerating. The rate of regeneration in the setup is great, I want the quick regen, but I want it to happen x seconds after taking damage, that way the damage isn't constantly fighting a constant regen. Here's what I did based on your image:

                          [ATTACH=CONFIG]95636[/ATTACH]

                          Also, this is the tutorial I used to setup my health system if that may give you an idea of how it works.

                          I appreciate your help!
                          I see. So after your character take damage (that should be on the Damage event), use the same Call function by Name, fill with your Health Regen function name and the Time will be the delay you want it to activate. This will be a delayed start for your Regen Loop.

                          To immediately stop the regen after you take damage, set the boolean IsRegenerating to false. When you call the health regen, it will make the rest for you.

                          You are welcome, hope this can work for you.

                          Comment


                            #14
                            After taking a look at the tutorial, if you've created the Damage Player function, you should put that setup I said last post inside this class.

                            After the Take Damage node, set the boolean IsRegenerating to false and call the Set Timer by function name here.

                            Take Damage -> Set bIsRegenerating = false -> Set Timer by Function Name = Name: Health Regen , Time: Delay to start regen

                            That might for you

                            Comment


                              #15
                              Originally posted by Gbr View Post
                              After taking a look at the tutorial, if you've created the Damage Player function, you should put that setup I said last post inside this class.

                              After the Take Damage node, set the boolean IsRegenerating to false and call the Set Timer by function name here.

                              Take Damage -> Set bIsRegenerating = false -> Set Timer by Function Name = Name: Health Regen , Time: Delay to start regen

                              That might for you
                              It doesn't seem to be working. I don't know if I may be doing this wrong though. The Damage Player function is in a library, while the regen function is in the character blueprint. Is this the right way to do it, or should I be doing everything in the library? The reason I ask is because the bIsRegenerating is in the third person blueprint, but not the function library. Making a replica doesn't seem to be doing anything.

                              Here is the damage player function, which is in the player function library:

                              Click image for larger version

Name:	dmgplayer.jpg
Views:	1
Size:	291.4 KB
ID:	1107519

                              And here is the health regen function in the character blueprint:

                              Click image for larger version

Name:	regen.jpg
Views:	1
Size:	259.7 KB
ID:	1107520

                              Caldera Entertainment | Twitter | ArtStation

                              Comment

                              Working...
                              X