Oscillator that doesn't have potential Divide By Zero problem

I tried to get ahead and made my own code for oscillating before watching this section. Mine seems to work pretty much the same as far as I can tell, except that it’s impossible to accidentally get a “divide by 0” error. Also it doesn’t involve anything about Tau.
Main difference is that instead of dividing by “period” I am multiplying by “speed”.
Any thoughts on this? Any pitfalls I’m not aware of?

public class Oscillator : MonoBehaviour

    [SerializeField] Vector3 movementVector = new Vector3(10f, 0f, 0f);
    [Range(0,1)][SerializeField] float movementFactor; // 0 for not moved, 1 for fully moved.
    [SerializeField] float speed = 1f;

    Vector3 startingPos;

    void Start()
        startingPos = transform.position;

    void Update()
        Vector3 offset = movementVector * movementFactor;
        transform.position = startingPos + offset;
        movementFactor = (Mathf.Sin(Time.time*speed)+1)/2;

So setting the “speed” to 0 just makes it not move at all, which I think is impossible with the other way to do this.

Privacy & Terms