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

Bandana Dee the Dream Friend

art comission.

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

Shadow The Hedgehog X pixel art

Terraria

Why walk when you can jump?

Alone Together....

Who's is this little cutey👸 here? Thanks🙏 for a gorgeous fanart @WheNa! Feel free to share your arts, screenshots, or videos with #playzelter or #zelter hashtags! #pixelart #animating #unity3d #animated #indiegames #unrealengine #animate #conceptart

If you’ve played the Vault demo and enjoyed it, please consider ‘liking’ the game page here on Gamejolt and/or leave a comment!

Also please consider tossing Vault on your Wishlist, I really appreciate your support!

https://store.steampowered.com/app/1251800