Oscillating a value using Lerp and Sin
I want to oscillate a value between a min and max range smoothly, starting from the minimum value.
I thought this would work:
void Update(){
_chargePower = Mathf.Lerp (_minPower, _maxPower, Mathf.Sin(Time.time - _startTime));
}
This works as you would expect, however, after lerping from the max back to the min, the value gets clamped at the min value, due to the Sin function -1 to 1 range.
I could use this to convert the Sin function into the 0 to 1 range:
float t = Mathf.Sin ((Time.time - _startTime) + 1f) / 2f;
However, this would mean the start value would be turned into 0.5, not 0. How can I smoothly lerp between a min and max range, starting at the min range?
Comment
Try this :
float sin = $$anonymous$$athf.Sin(Time.time - _startTime - $$anonymous$$athf.PI ) ;
float t = ( sin + 1 ) * 0.5f
This will still start in the middle of the range, but reverse the lerp. Should be pi/2 ?