In the real world, the sun always moves around the sky. To simulate that, is there a way to move the lens flare through script or other ways? I noticed that moving the direction light does not change where the flare is draw.
Can i emulate a sun like object by moving the Flare and changing the angle and intensity of the light?
I would appreciate it if any code is in JavaScript :)
To simulate that, is there a way to move the lens flare through script or other ways? I noticed that moving the direction light does not change where the flare is draw.
If you place a lens flare on the same object as your directional light, and set the lens flare to be directional, then it'll work just fine. No code required.
If your lens flare object and your light object are not the same, you can glue them to point in the same direction with a script that require you to bind the directional light to the script, and this script should then be on the lens flare (but the above approach probably is more elegant to use)
// Before using this script, review the first offered solution.
var directionalLight : Light;
function Update()
{
transform.forward = directionalLight.transform.forward;
}
Simple gotcha: Remember that you should rotate the directional light (and directional lens flare) instead of moving them by translation, as that information is ignored.
burgzergarcade.com has a series of video tutorials that detail day/night simulation, and although thorough enough to be easily replicated (the code is provided) it is done in C#.