NaN issue: Solved (1 method)

Hey everyone,

So this is the only solution I found to fix the NAN issue with the Zero Value:

if (period != 0) // !=0 to make the value strictly not equal to zero, negative values still work
        {
            float cycles = Time.time / period; // cycles we are going through, grows continually from 0

            const float tau = Mathf.PI * 2f; // never gonna chanve, tau is 2Pi = 6.28
            float rawSinWave = Mathf.Sin(cycles * tau); // raw value of the sin wave that is the number of cycles by tau which is equal to one cycle // goes from -1 to +1

            movementFactor = rawSinWave / 2f + 0.5f;
            Vector3 offset = movementFactor * movementVector; // displacement
            transform.position = startingPosition + offset;
        }

Unfortunately I do not have the sufficient knowledge in coding I’m still learning and I find this course really helpful and interesting. I think my biggest issue right now is that the math is scaring me a bit and I hope it won’t be much trouble in the future.

Big shout out to the Dev team behind this course!! :smiley:

And as always have a great day !!

2 Likes

Privacy & Terms