12 years ago

Day Night Cycle Tutorial


Hello,

I have decided to do what is basically a tutorial for a day and night cycle and because i know a lot of people use different languages i am going to show you how to do in terms of values the two values will be opacity (doesn’t have to be opacity, its just what i did for my game to show day and night i had a black sprite that i changed the opacity of so it apeared to get dark then light again) and i had another value which is used to change opacity

okay so i start out wanting to change the opacity from 0 (being mid-day and brightest it can be) up to 90 (being the darkest still slightly visible but very dark) and back to 0 this is the way i do it

first i wanted to do it in the easiets way possible and ebcause i do A-level maths i knew the best way would be to use a curve equation i could have used either a normal curve or i could have used a sine wave isf i wanted to but i just used a standard - x^2 equation ok this is the equation i used

y = -(x^2) + 90 (google it to see the graph of the wave)

this is the best way in my eyes to do it because you can just use the y value for the opacity

so this is what i did

i am doing it in english in case you use some weird language that i dont know

just a reminder i have two values opacity and value1

so i start off making value1 =-9.487

this because on the wave it crosee the x axis at this point so this is the time that will be brightest

now you have to decide youre time scale i am going to do mine in a minute (so one day will be a minute)

9.487*2 this gives the distance from each point it croses the axis

18.974/ timescale

18.974/60 (60 seconds in a minute)

0.31623333

0.3162 (rounded)

so every second add 0.3162 to value1 (-9.487)

so it will take 60 seconds to go from 0 to 90 back to 0

now we use the curve equation to make it go from 0 to 90

opacity = (-(value1^2) + 90)

now all we have to do is if value1 ever goes higher than 9.487 make it go to -9.487 so it cycles around

hopefully it makes sense to any of you if it doesn’t ask i might try and explain anything i made confusing



0 comments

Loading...

Next up

Did you know that today is #InternationalJazzDay? 🎷😎

No? 😯 Well, we couldn't pass up this date!

And what better to celebrate this day than #Pecaminosa #OST? 🎷

Let us know what you think about it and have a great weekend!

Been working lately on lots of 'behind-the-scenes' boring stuff that no one really cares about, so here’s a guy playing the sax for some reason.

#screenshotsaturday

Fan art for Foolish I'm feeling kinda better so I drew this

Finished a project I've been working on over the last few days!

Modeled and textured in Blender.

#3dart #lowpoly #npbr #fantasy #hut

"Our work is never over" they said.

Heya! I wanted to show some gameplay progress i made so far. I hope you like it ^^

Microsoft Windows XP Unprofessional (windows logo prototype)

A house I've built a while ago. :)

It nicely separates the snowy biome from the grassy one.

It's built with painted Ebonstone.

Showing off player 2 😎

What do you think?

Today I tackled drawing different variations of facial expressions for one of the main characters in Eden. What do you think of it? :) Eden: https://gamejolt.com/games/Eden/592698