How could I make light transitions smoothe?
Posted: Fri Jan 05, 2024 6:58 pm
I want the atmosphere to darken the higher the rocket in my game rises. I didn't want to hard code in the values so I decided to use modulo do increment or decrement the color of the sky based on the vertical distance travelled. I found that it does work but not as smoothly as I predicted since there are some moments where the color change is more drastic and less obvious.'
Here is the game to give full context:
Code: Select all
if Player.yVel < -10 and (distance % 100 >= 0 and distance % 100 <= 1) then -- distance is the vertical distance the player is from spawn
val = val - 1 -- val is the green light value of the background
val2 = val2 - 1 -- val2 is the blue light value of the background
elseif Player.yVel > -10 and (distance % 100 >= 0 and distance % 100 <= 1) then
if val < 150 then
val = val + 1
end
if val2 < 255 then
val2 = val2 + 1
end
end