Wrong angleThisFrame calculation in lesson

@ben

The equation used to calculate the angleThisFrame is dimensionally wrong:

  • Time.deltaTime is [sec]/[frame]
  • 360 is [degrees]
  • minutesPerSecond is [min]/[sec]

so angleThisFrame, dimensionally, is [sec]/[frame] * [min]/[sec] / [degrees], ending with a [min] / ( [frame] * [degrees] ), instead of the correct dimension of [degrees]/[frame]

The correct equation is

which gives a correct dimension of [degrees]/[frame], and if we set for example 60 minutesPerSecond, we get a complete day/night cycle in 24 seconds.

As a side note, I used only the Rotate() and no additional Quaternion variable:

[code]public class DayCycle : MonoBehaviour {

public float minutesPerSecond;

    float degreesPerFrame;

    void Update () {
        degreesPerFrame = minutesPerSecond * Time.deltaTime * 360 / 1440;
        transform.Rotate(degreesPerFrame,0,0,Space.Self);
    }

}[/code]

4 Likes

Wow, and I pride myself on dimensional correctness (I bang on about it in the Unity course).

I have patched this video with an overlay at 6:15.

Thanks so much, I really appreciate this sort of feedback.

1 Like