Why PI and cycles?

Hello. I’m sure this question has been asked before or maybe not… I’m confused why we are dividing
" Time.time / period " (I just don’t get it) why just not use " Time.time ".
Also why are we using Tau, why don’t we just use a specific number?
And how does the " cycles * tau " work if the Sin returns -1 or 1.
I used a different code which works the same(either I’m blind and can’t see the difference or it actually does work the same)

[SerializeField] float amplitude = 2f;
[SerializeField] float frequency = 2f;
movementFactor = Mathf.Sin(Time.time * frequency) * amplitude;

This leads to the same effect but without weird PI's or Time.time / period.
Maybe someone can explain more in detail why the code provided by this course is superior.

Hi,

I’ve already replied in your thread over on Udemy, so I’m just pasting my answer here.

Tau is defined as ( 2 * pi ). Pi is a specific value. You could type it or you could use the constant pi . We use tau because it’s a bit shorter than ( 2 * pi ).

Regarding your question about Time.time / period and other values, I’d suggest to simply test your idea in Unity to see what happens. Bear in mind that we use and modify the sine function to model a behaviour. When you change the values, you might get a different result, which is neither wrong nor correct but a matter of taste. Just as Ben’s approach.

Does Mathf.Sin(Time.time * frequency) * amplitude return a value oscillating between 0 and 1?

This topic was automatically closed after 6 days. New replies are no longer allowed.

Privacy & Terms