My first thought - if period is greater than 0 then do the movement, otherwise - don’t.
void Update ()
{
// set movement factor
if (period > 0f)
{
float cycles = Time.time / period; //grows continually from 0
const float tau = Mathf.PI * 2; //about 6.28
float rawSineWave = Mathf.Sin(cycles * tau); //cycles 0-1
print(rawSineWave);
movementFactor = rawSineWave / 2f + 0.5f;
Vector3 offset = movementVector * movementFactor;
transform.position = startingPos + offset;
}
}
So I got no warning in Visual Studio, but that could be due to lack of extensions that warn about things, as other posters have highlighted. Is this as bad/worse than the == technique? Which, coincidentally, didn’t actually occur to me at all. I don’t know if that’s good or bad!