- Home /
Trying to reset image settings on main camera smoothly
So I wrote a script that distorts the camera image when the player enters a trigger. I can get the image to distort fine and I use the Lerp function to do this, however I can not get the values to return back to 0.0f. I did look at the values directly and they seem to never arrive at the desired value. Here is the script, no compiler errors the image just stays distorted. Please help.
Answer by _Yash_ · Sep 21, 2016 at 01:11 PM
Comparing two floating point numbers is never a good idea,
if(disort.angle == 15.0f)
even, the way lerp is used here, it will never actually reach at 15.0 it may reach at 14.99999 but that is not equal to 15.0.
what you can do is check approximate value like this,
if(disort.angle > 14.8f)
but if you still want to reach at 15f you can use timer as third parameter of lerp.
if(timer < 1f)
{
.... = lerp( .... , 15f, timer);
timer += Time.deltaTime * smooth;
}
else
{
// reached 15 do deactivate
}