- Home /
Question by
mak431020 · Jul 23, 2021 at 02:11 PM ·
timetimer countdownrotatetowards
How to calculate time ?
i want to calculate how much time does it take to complete the rotation. How do i do that
void Update()
{
if(Input.GetKey(KeyCode.M)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(new
Vector3(90,0,0), 50f * Time.deltaTime);
}
}
Comment
Best Answer
Answer by tyruji · Jul 23, 2021 at 03:45 PM
It's actually pretty simple - all you have to do is get the angle difference and divide it by your rotation speed (50f in your case). example code:
float x_diff = 90 - transform.rotation.eulerAngles.x; // you're rotating to 90
float rotation_speed = 50f;
float estimated_time = x_diff / rotation_speed; // that's it
Be aware this won't work all the time, e.g. when your rotation is negative or above 90 it will break, but will still do it's job if you have a rotation from 0 to 90 max. Good luck!
Your answer
Follow this Question
Related Questions
How do I make a Countdown Timer in Minutes and Seconds only 1 Answer
timer not ticking down 2 Answers
Visual timer? Like CUT THE ROPE 2 Answers
time synchronization via Photon 1 Answer
Subtract milliseconds from 12 hours? 1 Answer