Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jun 23, 2015 at 02:33 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CB-TV · Jun 23, 2015 at 01:48 PM · variableincreasedecrease

1 Variable Affected By Multiple Variables

I would like to have a large float affected by multiple other floats. Right now I have this:

 energy -= thirst + temperature  + hunger  + tiredness;

These variables get bigger every second which means the rate at which Energy decreases is vastly increased over time. I do not want this. Is there a way for energy to be decreased at a rate depending on these variables or would I have to reverse these variable's affects (such a decrease thirst instead of increase it and add the variables together to equal energy)

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by meat5000 · Jun 23, 2015 at 02:01 PM

Add some scale factors.

 energy -= (a * thirst) + (b * temperature)  + (c * hunger)  + (d * tiredness);

a b c and d can be set to some decimal value (<1) to reduce the impact of the variables on the energy. You can use these as modifiable stats as an in game skill-tree or some nonsense so they player could acquire some resistance to temperature, for example.

So, above, if a = 0, thirst has no impact on energy. If a = 1, thirst has full impact (Or more if you make a > 1!!).

You go to a hot place. You can simulate this easily by increasing a and b to be > 1.

Comment
Add comment · Show 1 · Share
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 CB-TV · Jun 23, 2015 at 02:20 PM 0
Share

Thanks for the info!

avatar image
1

Answer by Ibzy · Jun 23, 2015 at 02:00 PM

My approach would be to first figure out what rate I would want energy to decrease at in the worst scenario. So with zero thirst, hunger, temp, and tiredness, the energy will not decrease as player is in top form. Assuming the 4 variables are 0-100:

 int energyDecreaseRate = 1; //eg. 1 energy per frame
 float energyDecreasePerc;
 
 void Update(){
     energyDecreasePerc = ((thirst+temp+hunger+tireness)/4)/100;
     energy -= (1 * energyDecreasePerc) * Time.deltaTime;
 }
Comment
Add comment · Show 6 · Share
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 CB-TV · Jun 23, 2015 at 02:20 PM 0
Share

Ah, thank you!

avatar image Ibzy · Jun 25, 2015 at 03:06 PM 0
Share

What part are you struggling with?

This approach is giving the 4 variables equal effect on energy, and then reduces the energy by a percentage of your potential worst energy decrease(here "1").

e.g. Thirst:50, Temp:30, Hunger:21, Tiredness:73 50+30+21+73 = 174 / 4 = 43.5 /100 = 0.435 (43.5%) Energy is decreased by 0.435 per frame. At best state (just drank, eaten, slept and at average temperate) Energy will not decrease at all.

I have just noticed though, "tireness" should be "tiredness" and line 6 should read:

 energy -= energyDecreaseRate * energyDecreasePerc) * Time.deltaTime;
avatar image CB-TV · Jun 25, 2015 at 03:08 PM 0
Share

It's weird, energy does not decrease at all for me?

avatar image CB-TV · Jun 25, 2015 at 03:10 PM 0
Share

Ah, I've found it out. $$anonymous$$ost of my variables are 0, so energy is just decreasing at a really slow rate. Thanks!

avatar image CB-TV · Jun 25, 2015 at 03:12 PM 1
Share

No, energy isn't an int, it's just that it's reducing really slowly, which is actually what I want.

Show more comments

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Adding a value to a variable every second 4 Answers

How Return Or Restart A Coroutine When A Variable Increase? 1 Answer

Variable not decreasing during runtime (C#) 1 Answer

Variable not Updating 2 Answers

Need health to decrease with movement in Javascript 1 Answer


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