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

One of the most critical update for Sunblaze demo. Now you are able to pet a cat! Finally!

Demonstration of the spells and their effects :)!

Horror WIP A track that will be featured in a future horror game soundtrack! Stay tuned!

Likes appreciated ✌️

#gamedev #composer #horrorgame #indiegame #IndieGameDev #soundtrack

Update 2.627

New challenges & new effects!

Terraria

I worked so hard to get all four of them to the end safely, but then...

Cash Banooca

not the greatest house, but it's a house! :D

I mostly build 3D First Person Shooter game mechanics in Unity, and in this I'm just showing C4 mechanics I made for a little side project I am working on! :)