Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mrroundtree22 · Jul 21, 2016 at 06:42 PM · fpsdynamichudhealth

First person shooter : Fight night champions dynamic health bar

I was interested in adding a health bar to a game i'm making similar to the one found in the "Fight night" game series more specifically "Fight night : champion". The general idea is to have a health bar which regenerates quickly but slowly depletes in size the longer it stays empty.

This would add challenge to the game as getting hit by a bullet may not have an adverse short term effect because your health regenerates rather quickly but long term speaking your overall health bar will be smaller and you will not be able to absorb as much damage as you did before and will force the player to act more carefully in the future.

I usually prefer to use visuals to illustrate what I mean but unfortunately I can't find anything, other then videos, so I apologize if it is a bit cryptic. I will try to explain further if asked to do so.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Jul 21, 2016 at 06:48 PM 0
Share

So, what have you tried so far? there are lots of health bar tutorials available, so it sounds like you need help with the logic. With some experimentation with CoRoutines, WaitForSeconds and booleans you should quickly get there. Do you have any specific questions regarding what I outlined above?

avatar image Mrroundtree22 Cherno · Jul 21, 2016 at 06:58 PM 0
Share

Well I am a beginner, more or less, so I've watched some tutorials on youtube on how to make a health bar and I figured perhaps that adding a feature that makes the health bar deplete overtime can't realistically be that much extra work to implement.

I just don't know how to do it though, that's the issue, I guess I just need an example to go by that usually seem to help me understand and learn the best.

How would you go about doing this? Which method do you recommend?

avatar image Cherno Mrroundtree22 · Jul 21, 2016 at 07:43 PM 0
Share

So for the health attribute, we need a few values: 1. $$anonymous$$ax health. This is the value that will get lower with replenishing. 2. Current health. Thus is the value that will be replenished continually if below max health. 3. Replenish speed. The time factor that controls how fast the current health replenishes.

With these values, we can make the "theoretical/logical" part of the health system (the practical part would be representing it on the screen with a bar, and needs values for the health bar max and current length).

 public float maxHealth = 100f;
 public float curHealth = 100f;
 public float replenishSpeed = 2.5f;
 
 public int healthBarLength_max = 20;
 public int healthBarLength_cur = 20;
 
 void Update() {
      if(curHealth < maxHealth) {
            curHealth = $$anonymous$$athf.Clamp(curHealth + (Time.deltaTime * replenishSpeed), maxHealth); //so it will never go even slightly above maxHealth
 
        healthBarLength_cur = $$anonymous$$athf.RoundToInt(healthBarLength_cur / healthBarLength_max * curHealth);
       //pass this value to your healthBar UI element, depending on how you implement the visual aspect
       //updating the length could also be done in the TakeDamage function; it doesn't really need to be updated every frame.
 
      }
 public void TakeDamage(float receivedDamage) {
       curHealth = $$anonymous$$athf.Clamp(curHealth - receivedDamage, 0); 
      maxHealth = $$anonymous$$athf.Clamp(maxHealth - receivedDamage, 0); 
      if(curHealth == 0f) {
             //Die!
       }
 
 }
 }
 


0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Health not working! 1 Answer

Empty Health Bar, remove one life 2 Answers

Health Script 1 Answer

Health and ammo GUI not working on re-spawn 0 Answers

Deal damage on collision 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges