Hi all!
What I am making is a kind of a glitch effect, where I need a float value x to lerp between two values a and b in a kind of a random manner.
So what I would like is for x to lerp from a to b, and then back to a. And I thought that a sine wave set to a 0-1 range would do the trick. But what I would additionally want is for the sine wave to trigger randomly.
To put it simply. I need a sine wave that has a random length pause between each wave.
What I am trying to portray here is that in the “What I want” there are sine waves/peaks being spawned in randomly.
Not sure if this is useful - it was something I was doing today which is sort of related - a random (pseudo-random) sine pattern, made from compounding a few sines to mess them up.
void Update()
{
float a = Mathf.Sin(Time.time * 1.00f) * 0.5f;
float b = Mathf.Cos(Time.time * 5.43f) * 0.4f;
float c = Mathf.Sin(Time.time * 8.72f) * 0.3f;
float d = Mathf.Cos(Time.time * 17.3f) * 0.2f;
float e = Mathf.Sin(Time.time * 23.7f) * 0.1f;
transform.position = new Vector3(Time.time*3, a+b+c+d+e, 0);
Hopefully you can see what’s going on here . . . . the multiplier directly after each ‘Time.time’ part is how fast the sine is going up and down - and then the multiplier right at the end of each line is how far up and down the sine swings from 0 (so for example with the first line the range of movement is 1, made up of 0.5 up and 0.5 down).
The the actual transform.position part just moves the cube along using Time.time . . . and then then various sine values are all added together to produce a random-ish Y movement. By the way some of the values are Cos rather than Sin, no particular reason, they could all be one or the other, just trying to get a more random pattern.
If you want the total maximum up and down movement, just add up all the multipliers at the end of each line to see what it will be - in this example the total range of movement is 3 . . . 1.5 up (above 0) and 1.5 down (below 0).