- Home /
How to script a seconds hand of a clock
Hello All
How to script a seconds hand of a clock, the seconds hand of a clock should rotate and stop for a second and rotate again and stop for a second and so on. I tried doing it but it gives me continuous rotation and i dont want that. Thanks in advance.
Answer by robertbu · Jul 01, 2013 at 06:44 AM
One way is to use a curve. X^5 will work:
#pragma strict
private var timer = 0.0;
function Update () {
timer += Time.deltaTime;
timer = timer % 60.0;
var fractionTime = timer % 1.0;
var baseTime = timer - fractionTime;
var angle = baseTime * 6.0 + Mathf.Pow(fractionTime, 5.0);
transform.eulerAngles = Vector3 (0.0, 0.0, -angle);
}
If you want even more control, you can use an AnimationCurve rather than Mathf.Pow(). For example, you might want the second hand to overshoot the second position and snap back each time it ticks. This could easily be done by substituting an animation curve.
Your answer
Follow this Question
Related Questions
Minutes and Seconds in a text 1 Answer
Loading A Level After 40 Seconds 2 Answers
Moving elevator based on specified time limit 1 Answer
why the debree timer float not work 1 Answer
clock second smooth movement 1 Answer