(Post Processing) How to make the Lens Distortion go up and down all the time?

Hello! :slight_smile:

As the title states, I want the Lens Distortion PP value to go up and down all the time (think of like someone moving the slider from the left to the right and back all the time :smile:)

What we currently have is kinda weird, looks good with not a lot of distortion but if I increase the numbers it behaves weirdly? (when it comes close to zero it gets super slow and sometimes itโ€™s stuck to a value)

This code is used:

distortion.intensity.value += Mathf.Abs(distortion.intensity.value) > 1.0f ? Time.deltaTime * 60.0f : 10 + Time.deltaTime * 60.0f;
} else {
distortion.intensity.value -= Mathf.Abs(distortion.intensity.value) > 1.0f ? Time.deltaTime * 60.0f : 10 + Time.deltaTime * 60.0f;

Is there another way to do this?
Further info: Programmer is currently annoyed with the project so I wanna research for him :slight_smile:

Haha, can I hire you? :wink:

You could try something like this:

const float speed = 1.0f;
const float minDistortion = 0.0f;
const float maxDistortion = 1.0f;
float t = (Mathf.Sin(Time.time * speed) + 1.0f) * 0.5f;
distortion.intensity.value = Mathf.Lerp(minDistortion, maxDistortion, t);
1 Like

Sure! Please note that Iโ€™ll have you appreciate that I charge $0.20 whenever the solution I found for your is used in your code! :smile:

Aww thanks!! โ€œIโ€ will try that and let you know how it works out :smile: (probably a bunch of compliation errors until I can kick him to his PC to make a pull request, but fingers crossed, hehe:))

1 Like

Just realized that you are making a joke about the new license terms LOL (this took me much longer than it should have). Yeah, I think they are ridiculous too. Professionally, Iโ€™ve already moved on to UE but I love the Unity community and will probably continue posting here.

1 Like