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 /
avatar image
0
Question by CarlVercetti · Sep 04, 2014 at 05:07 PM · timevaluecyclesundaynight

Increase a variable from a value to another value in a range of time

Hello guys, I'm here to ask you an advice because I don't have any idea D: . Sorry for the title, it's not easy to describe this problem in a simple sentence. So I'm making a Night Day Cycle (I followed the BurzBurg Arcade Tutorial, but I'm making my own now inspired by Burz) and I have a problem with the Sunset and Sunrise.

My goal is to decrease/increase the light of the sun pretty well (when it's midday, the Intensity of the sun must be 1, when the sun sets, the intensity must be 0).

I split the day in 5 moments: Sunrise, Midday, Noon, Sunset and MidNight and every moments begin at a specific "hour" (for example: a day is 60 seconds long, so midnight will be 0, midday 30 (DayDuration in Seconds / 2), etc...

I have a variable called ActualTime that increase at every frame and it's porpouse is to keep up the time like a clock.

So the morning will be long (Midday - Dawn). My problem is that I can't figure out the operation to make sure I have a correct increase value for the sun's light in a way that, when is Midday, the intensity will be 1, and even if I change the Duration of the day, the sun will always have 1 of intensity when is Midday.

This is part of the code, the increaseRate is wrong

 IncreaseRate = (Midday - dawn) /1000f;
 if((_ActualTime > Dawn) && (_TempoGiornaliero < Midday)) {
  if (Suns[0].light.intensity <= 1.0f){
  Suns[0].light.intensity += IncreaseRate * Time.deltaTime;
   }
  }

I want to make something like this:

When the Dawn begin, the sun's intensity begin to increase so when it's Midday, the intensity will be 1, but in that moment, not before, not after.

My scripts can work with "custom value" that I can put in the inspector... but I never liked this kind of solution :P. I know that the solution will be pretty simple, but right now I don't have any ideas D:.

Sorry for the bad explanation. Have a nice day!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Baste · Sep 05, 2014 at 11:02 AM

There's a great trick you can do here with animation curves.

First, attach a public animation curve to your script:

 public AnimationCurve lightCurve;

You'll use this to set the light of the "sun" at different points of the day. Go to the inspector, and click the lightCurve part of your script, and you'll get an editor. Set the values of the curve by double clicking to make points, and dragging them around.

You say you want midday intensity to be 1, and 60 second day cycles. Then you should make a node at 30 on the time (x) axis and 1 on the value (y) axis, with the 0 and 60 points having a value at or close to 0:

alt text

Then, in your script, you set the light intensity to the value of the curve at the current time. In your code, this would be:

 Suns[0].light.intensity = lightCurve.Evaluate(Time.time % 600000)

% 600000 makes the evaluation wrap every 60000 milliseconds, or 60 seconds. So when you get to 61 seconds, the curve is evaluated at 1 seconds.

I hope that helps! In general, animation curves can be used for an amazing range of things to jumping and knockback patterns to whatever. The Animation part of the name isn't something you should care too much about.


curve.png (51.5 kB)
Comment
Add comment · Show 2 · 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 CarlVercetti · Sep 06, 2014 at 08:59 AM 0
Share

Thank you! I will use this trick for the Sun Light and for the Ambient Light too!

avatar image Baste · Sep 11, 2014 at 10:46 AM 0
Share

Great!

It'd be nice if you could mark the answer as accepted, so it disappears from the list of unanswered questions. :D

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to change a value over time in a coroutine ? 2 Answers

Make value change to anoter over time and back loop 3 Answers

Reducing a value over time 2 Answers

Realtime daylight cycle? 1 Answer

UI Slider Value Increases Far Too Slowly With Controller. 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