Skip to content
ReadySpawn

Horror lighting in Unity: flickering lights and fog

By Imersa Studios · Updated

Turn ambient light almost off, add short exponential fog, and put a flicker script on your few lights. Noise-based flicker feels more organic than random values. The script below is a drop-in component.

1. Set the mood first

  • Lighting settings: set the ambient colour to a very dark blue or grey.
  • Fog: enable it, mode Exponential Squared, a dark colour that matches the ambient, density about 0.05 to start.
  • Use few lights and make each one count.

2. The flicker script

Attach it to a Light. It mixes Perlin noise with rare dropouts, where the light cuts for a moment.

using UnityEngine;

// Put this on a Light. Noise-based flicker feels organic; a random "dropout" adds a scare.
public class FlickerLight : MonoBehaviour
{
    public float baseIntensity = 1.2f;
    public float flickerAmount = 0.6f;
    public float speed = 8f;
    [Range(0f, 1f)] public float dropoutChance = 0.02f; // per frame at 60 fps
    public float dropoutSeconds = 0.12f;

    Light lamp;
    float seed;
    float offUntil;

    void Awake() { lamp = GetComponent<Light>(); seed = Random.value * 100f; }

    void Update()
    {
        if (Time.time < offUntil) { lamp.intensity = 0f; return; }
        if (Random.value < dropoutChance * Time.deltaTime * 60f) offUntil = Time.time + dropoutSeconds;

        float n = Mathf.PerlinNoise(seed, Time.time * speed);
        lamp.intensity = baseIntensity + (n - 0.5f) * 2f * flickerAmount;
    }
}

Tune the pattern without writing code in our flicker light generator.

3. Rules that keep it scary

  • Light the path you want the player to follow, and leave corners dark.
  • Flicker only a few lights. Everything flickering is noise, not fear.
  • Pair a flicker with a sound cue for the best effect.

Questions

Who wrote this

Imersa Studios builds the Unity systems, low poly packs and field guides sold on itch.io. The code and techniques here come from shipping those products. More about the studio.