My solution

    void Update()
    {
        // auto set movement factor

        if (period == 0){
            
        }
        else
        {
            Oscillate();
        }

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

    private void Oscillate()
    {
        float cycles = Time.time / period; // grows continually from 0

        const float tau = Mathf.PI * 2; // about 6.28
        float rawSinWave = Mathf.Sin(cycles * tau); // goes from -1 to +1

        movementFactor = rawSinWave / 2f + 0.5f;
    }
}

I was honestly really surprised it worked and that I got it to work lol

1 Like

WOOHOO! I am happy for you! You got it to work on your own!

1 Like

Nice work mate I went the same path, just slightly different

void Update()
    {
        if (period != 0)
        {
            MoveObject();
        }
        

    }

Privacy & Terms