- Home /
Sun rotation glitchy
Hello,
I am making a 3d game with day/night cycles. I am rotating the directional light that is default to a unity 3d scene using the line below in a script's update method to cause the rotation of the sun.
gameSunLight.transform.Rotate(degrees, 0, 0);
The problem is that i notice a bit of glitchiness that goes away when i comment out this line. I've looked at the profiler and the script section of the profiles reports 0 ms delay for this so I'm assuming the rotation is causing a rendering delay.
I've tried other variations of the Rotate method, but they all seem to have the same effect.
I'm fairly new to Unity so it may be something obvious or it just may be the cost of rotating a light. Either way i appreciate any help.
I'm using default lighting settings, and the default light object that is setup when you start a new scene, but my terrain is fairly big and complex.
Thanks,
Paul
Glitchy doesn't really say much about what you're seeing. We probably need to see how degrees is incremented.
Sorry i should have been more detailed. By glitchy i mean as you move the mouse to look around in the game (using the standard assets Unity FPS character) it is not as smooth as it is with that line commented out. Not that the frame rate is a lot lower, but more like it periodic frame skipping or something. glitchy is probably the best word to describe it. While running with the the rotation it is most noticeable when moving around. if i comment it out the looking around movements are smoother, less glitchy.
The degrees variable is a constant float so i can control the rotation. When i comment out the rotation line it goes away so i know thats the problem.
I'm newer to unity so I'm not sure if im missing something with the lighting settings or something that would improve performance. I have it on the default settings.
Ok, glitchy is now clearer. I still suspect the means by which 'degrees' is incremented. That fits with your description. If the rotation isn't being applied, and movement looks ok, but then it gets glitchy when rotated, my assumption is that 'degrees' is being incremented by values large enough to make the position jump rather than smoothly move from frame to frame. So, how is 'degrees' incremented?
degrees is a constant. it is set to .02f, i just used the constant so i could change the value at the top of the code rather than find it in the code when i want to use a different sun speed. I replaced it with gameSunLight.transform.Rotate(0.02f, 0, 0); and get the same result.
the rotate method moves the sun .02f on the x axis for each frame update. I'm starting to think i am just seeing the cost of rotating a light that casts shadows, but I dont see anything in the forums that cover that as an a less efficient thing to do.
@masterofcodepc On a hunch, try 0.005f and see what happens.
Your answer
Follow this Question
Related Questions
Is it possible to rotate the environment's reflection source at runtime? (C#) 1 Answer
Light intensity Problem in unity 2D 0 Answers
How do I make a spotlight make a model play an animation? 2 Answers
Add Light Source to Sun in Environmental Lighting with Unity 5 by Script? 3 Answers
Instantiated light not working properly 0 Answers