It looks like I have an error in the code but it's working. Why?

Hi, I think I managed to protect my code against NaN, but Visual Studio keeps showing me this “error” message even with the game working as expected and not showing any error messaged into the console.

In “if (period == 0)” I can see this message in yellow: “fly floating number comparing. Compare a difference with epsilon”

I didn’t understand whet it means…

void Update()
    {
    
        if (period == 0)
        {
            transform.position = startingPos;
        }
        else
        {
            Oscillate();
        }

       
    }

    private void Oscillate()
    {
        float cycles = Time.time / period;
        const float tau = Mathf.PI * 2f; 
        float rawSinWave = Mathf.Sin(cycles * tau); 

        movementFactor = rawSinWave / 2f + 0.5f;

        Vector3 offset = movementVector * movementFactor;
        transform.position = startingPos + offset;

    }```

Oh, I just saw that the answer for this challenge on video explains this. :smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms