# How can I change number range dependent on a dot product

Hey guys.

I’m trying to make a feature where, whenever you look at a clock your screen turns dark. But I’m trying to make it so that the closer the clock is to the middle of your screen the darker the screen gets. Here is the script I’m using:

When the dot product is less than .4 the clock is off screen, but when it is higher than .4 it is on screen.
What I’m trying to achieve is to make the value 1 when the dot product is at .4, and 255 when the dot product is at 1 (or as close as it can get to 1)
The problem is that the value is at around 110 when the dot product is at .4, and I do now know how to fix this.

Can anyone help?
Thanks!

Why dont you do:

``````if dotProduct > 0.4 then
local fov = 255 * (math.abs(dotProduct) / 0.4)
end
``````

You multiply `255` by the percentage of the `dotProduct` from `0.4`.

That only increases the value, sadly.
I want it to decrease to 1 the closer the dot product is to 0.4
and increase to 255 the closer the dot product is to 1

I got it backwards, sorry (I did from 0 - 0.4 instead of 0.4 - 1). Here’s the proper code:

``````if dotProduct > 0.4 then
local fov = 255 * ((math.abs(dotProduct) - 0.4) / 0.6)
end
``````
1 Like