- Home /
Rotating Sun?
Hello im quite noob at Unity but i have a handle on the programming part, just wondering how i can make a sun (light) rotate areoung a terain.. Kinda like the sun rotating around the earth, so i wanna create the sense of dat and night... And also can we make this dynamic so i can apply the code somehow to any object so that it rotates around in the same way. Remember RotateAround wont work, because i have rectangular terrain..
Answer by Chimera3D · Jul 01, 2012 at 02:35 AM
Okay this won't be a dynamic day/night system but if you just want to rotate a directional light couldn't you just use a simple animation? Window > Animation, select the light, hit the record icon, record your animation, loop it, hit play, done...
EDIT: Here's a code.
var dayLength : float;
var rotationSpeed : float;
function Update () {
rotationSpeed = Time.deltaTime / dayLength;
transform.Rotate(0, rotationSpeed ,0);
}
But the issues is that i want to set the time taken, etc... I want code. :)
Thanks, only 1 issues, its just spinning its not moving around the terrain.. so would i use RotateAround?? If so how?
Answer by Eric5h5 · Jul 01, 2012 at 02:36 AM
You don't have to actually move the light, you can just rotate it by using Transform.Rotate. Since it's a directional light it doesn't matter where it is, only in what direction it's pointing.
But it's rotating a rectangle so it cant rotate in a circle so to speak but rather a oval.
Answer by RCraig · Jul 11, 2012 at 05:07 AM
Use iTween on your light with an oval path using a looktarget. Create your path in an oval shape around your terrain and name it, create an empty game object at the center of your terrain, and set the looktarget transform in the iTweenEvent to the empty game object.
*Play Automatically
Event Type: MoveTo
Path: The named path you created
looktarget: transform: empty game object
time: How many seconds you want a whole day/night cycle to last
easetype: linear
looptype: loop
Leave everything else unchecked. Then just make your actual visible object a child of the light and zero its transform. Hit play and you should have a sun rotating around your world, with the directional light rotating accordingly.
Answer by Ingen · Jul 11, 2012 at 04:04 PM
Hy
take a look at this
http://answers.unity3d.com/questions/56379/can-i-ask-for-a-daynight-cycle-script-for-free.html
http://www.youtube.com/watch?v=zxIyZzieFqE
some time a shoot on google can help
Your answer
Follow this Question
Related Questions
Temporary Rotation 2 Answers
Issues rotating around transform.up 2 Answers
Flip over an object (smooth transition) 3 Answers
change just z axis angle 1 Answer
What is wrong with this script? 2 Answers