My solution, it seems to work, but is it okay?



here is my protection against NaN. I am wondering since it gives me no problems (or yellow underline), but is totally different than Ben’s, if it is a potential minefield.

 if (period != 0f)
            float cycles = Time.time / period;
            const float tau = Mathf.PI * 2;
            float rawSineWave = Mathf.Sin(cycles * tau);
            float movementFactor = rawSineWave / 2f + 0.5f;
            Vector3 offset = movementVector * movementFactor;
            transform.position = startingPos + offset;


That is basically what I did too, and I have the same question. I have quite a bit of code at this point that is different than what Ben has done and even though my level seems to work fine, I keep wondering if I am really hurting myself by not just using his code.


I also did it this way. I believe Period=0 needs to be allowed from a game design point of view. Auto-adjusting it to anything other than zero would impart movement on an object that you might need at some point to be stationary.