Sun Variable Rotation
Hey, I'm trying to write a script that will allow the sun to rotate between different angles at differing speeds... So it rotates from 30° at 4am to 60° at 6am - then from 60° to 120° at 6pm - then from 120° to 150° at 8pm - so the sun moves 3 times faster in the morning and dusk basically...
I'm doing this to avoid long shadows as the day begins/ends that I seem to get with various day / night assests I've used, and also make the middle of the day last longer.
The times 4am, 6am etc. will change based upon the in-game season too, just FYI.
Any help would be greatly appreciated.
(Attached pic may be easier to understand than explanation) [1]: /storage/temp/161991-mfsun.png
Answer by SiniKettu_ · Jun 19, 2020 at 10:05 AM
I would recommend to create an animation of your sun, in which you can make the sun going three times faster during morning and dusk.
You can easily create an animation in Unity. If you don't know how : https://docs.unity3d.com/Manual/animeditor-CreatingANewAnimationClip.html
Another suggestion : create a curve on a mathematical software (i would use Xcas or Geogebra) and to a function because you seem to need a mathematical function which follow this kind of curve :
Another suggestion : you can create a custom graph as a variable in Unity, which is editable from the inspector. And then your script will be able to read the Y value for a given X value.
Put a public variable in your class with the type AnimationCurve:
public AnimationCurve myCurve;
You can evaluate the curve (get the y for an x value) with:
float y = this.myCurve.Evaluate(x);
I hope i'm useful
Or you can do multiple linear functions which fit with what you want
So it rotates from 30° at 4am to 60° at 6am - then from 60° to 120° at 6pm - then from 120° to 150° at 8pm - so the sun moves 3 times faster in the morning and dusk basically...
"I hope I'm useful" - lol :) Thank you so much, I'll have a look into the methods you suggested!
Your answer
Follow this Question
Related Questions
A game object like a snake but cluster of lights while going 0 Answers
How do you continuously rotate an object? 1 Answer
Rotate player with mouse. 0 Answers
Touch Inputs 1 Answer