Unity3D – Playing around with the terrain creator (4)

I decided the next step in my terrain project was to make night and day cycles. The first step in this was to make the sun rotate and have its brightness vary depending on heights, the moon and its light came later.

The sunController script moves the sun. It also calculates the sky color (using lerp), the lens flare, the lighting intensity and the color of the water. Currently the sun and moon start on opposite ends and rotate at the same speed, this is easily changed via the public variables in the 2 scripts.

This is pretty much all the code (minus the declarations) for the sunController. The first part both rotates the sun then changes lens flare and brightness depending on its height. The second part lerps the sky and water color depending on the suns height. Above a certain height (yHeight4BlueSky) the sky is at full intensity.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s