Moving in a wave pattern [solved]

I’m trying to make an enemy that just flies forward in a simple wave pattern. But for some reason my variables are not working the way I would expect them to.

Called from Fixed Update:

            newVelocity.x = forwardSpeed;
            newVelocity.y = magnitude * Mathf.Cos(Time.time * waveSpeed);
            rBody.velocity = newVelocity;

The magnitude works, I can make the wave go out wider or tighter.
But the wave speed just applies the magnitude in reverse. If I increase the wave speed the object just moves in a tighter wave.

I want to adjust it so that magnitude dictates how far up/down the object moves, and waveSpeed dictates how quickly it reaches that peak of how far up/down it moves.

I’m confused here because I’ve done bobbing objects before, and this is the same math I used. I looked around for instructions on how to make something move in a wave pattern, and this is the same math they use. So why is my waveSpeed just constricting the wave?

Did you try dividing the time by waveSpeed? I don’t know anything about this, but it seems like you would use time between frames rather than the time from game start.

After some experimentation and some trial and error, I discovered that I can get the result I want if I scale the magnitude with the wave speed. The wave speed DOES increase but at that higher speed the magnitude is reduced.

I can solve this issue by simply adjusting the magnitude variable as well as the wave speed.

…or by including that calculation in the code:

            newVelocity.x = forwardSpeed;
            newVelocity.y = magnitude * waveSpeed * Mathf.Cos(Time.time * waveSpeed);
            rBody.velocity = newVelocity;