function init()
  SunHeightStart = -1
  SunHeightEnd = 210
  SunHeight = SunHeightStart
  SunDistance = 100
  SunTimeToRise = 130 -- in seconds
  rising = false
  startpos = nil
  Time = 0
  frac1 = 0
  frac2 = 0
  frac3 = 0
  frac4 = 0
  SetValue("frac1", 0.5, "linear", 1)
  SetValue("frac2", 0.1, "linear", 1)
  SetValue("frac3", 0.2, "linear", 1)
  active = true
  rotated = false
end
function tick(dt)
  local ct = GetCameraTransform()
  if active == true then
    active = false
    rising = true
    SunHeight = SunHeightStart
    SetValue("SunHeight", SunHeightEnd, "linear", SunTimeToRise)
    local dir = TransformToParentVec(ct,Vec(0,0,-1))
    startpos = VecAdd(ct.pos,VecScale(dir,SunDistance))
  end
  if rising then
      SetEnvironmentProperty("sunDir", 0, SunHeight, 10)
    if rotated == false then
      local pos = VecAdd(startpos, Vec(0,SunHeight,0))
      local rot = QuatLookAt(pos, ct.pos)
      local t = Transform(pos,rot)
      local x,y,z = GetQuatEuler(rot)
      skyboxrot = y
      SetEnvironmentProperty("skyboxrot", 360-skyboxrot)
      rotated =true
    end
    Time = Time + dt
    if Time > 0 and Time < 1 then
      SetEnvironmentProperty("skyboxtint", frac1, 0.0, 0.0)
      SetEnvironmentProperty("fogcolor", frac2, 0.0, 0.0)
      SetEnvironmentProperty("skyboxbrightness", frac3)
      SetEnvironmentProperty("constant", 0, 0, 0)
      SetEnvironmentProperty("sunBrightness", 1)
      SetEnvironmentProperty("sunSpread", 0)
      SetEnvironmentProperty("sunLength", 32)
      SetEnvironmentProperty("sunFogScale", 1)
      SetEnvironmentProperty("sunGlare", 0.8)
      SetEnvironmentProperty("exposure", 1, 5)
      SetEnvironmentProperty("brightness", 1)
    end
    if Time > 1 then
      local sun_direction = VecNormalize(Vec(0, SunHeight, 10))
      sun_direction = QuatRotateVec(QuatEuler(0, skyboxrot, 0), sun_direction)
      local sun_position = VecAdd(GetCameraTransform().pos, VecScale(sun_direction, SunDistance))
      local hit = QueryRaycast(sun_position, VecScale(sun_direction, -1), SunDistance+1, 0, true)
      if hit == false then
        healing = false
        SetPlayerHealth(0.0)
        canheal = true
      end
      if hit == true then
        if canheal == true then
          healing = true
          canheal = false
        end
      end
      if healing == true then
        SetPlayerHealth(0.0)
        healing = false
      end
      SetEnvironmentProperty("skyboxtint", 1.0, 0.0, 0.0)
      SetEnvironmentProperty("skyboxbrightness", 0.3)
      SetEnvironmentProperty("constant", 0, 0, 0)
      SetEnvironmentProperty("ambient", 0.2)
      SetEnvironmentProperty("fogcolor", 0.13, 0.0, 0.0)
      SetEnvironmentProperty("sunColorTint", 1.0, 1.0, 1.0)
      SetEnvironmentProperty("nightlight", false)
    end
  end
end