Tween between two Mathf.Sin oscillations??

I’m stumped. I’m using a simple formula to smoothly oscillate a game object up and down. I can, say, make it have a large range and move slowly, like this…

void Update()
{
   transform.position = new Vector3(0, (Mathf.Sin(Time.time * slowSpeedFloat) * bigRangeFloat), 0);
}

…or I can have it move quickly over a smaller range using the same formula, just with different modifying vars, like this…

void Update()
{
   transform.position = new Vector3(0, (Mathf.Sin(Time.time * fastSpeedFloat) * smallRangeFloat), 0);
}

…but HOW do I transition/tween from one type of speed/range to another over time? I’ve of course tried tweening or Lerping the vars that control speed and range, but the oscillation gets pretty wonky during the tween before settling into the new oscillation. But I need that transition to be smooth as butter too.

Thanks in advance for any ideas or direction.

The lerping between bigRangeFloat and smallRangeFloat is not a problem as this just scales the curve, so this looks smooth if you don’t go too fast.

The problem is that Time.time is a pretty big number… it changes at a constant speed, but the number is huge compared to 2piyourConstant.

So if you change your constant just a tiny bit … say from 1.01 to 1.02 and time is at 100000 seconds, the wave jumps 100000*0.01=1000 which is hundreds of wavelengths, so it’s basically random where you land.

Now what you can do is keep that time number small…
instead of Time.time, use this:

float t = Time.time % (2*Mathf.PI);

or even better, to not get problems with float precision limits, do this in update:

t = (t+Time.deltaTime) % (2*Mathf.PI);

Now this should solve your problem if your slowSpeedFloat and fastSpeedFloat are not far away from 1.0

If you still have problems, we need to dig deeper in our mathematical pockets and scale around the current time value which will give you a perfect result no matter what.