That was lighting... and thunder.
You might know that when lightning strikes, the thunder is almost always delayed by some time. The
flash appears first, and then the thunder follows. This is because the speed of light is much,
much faster than the speed of sound. While the light from the lightning flash reaches
you almost instantly, the sound from thunder actually takes a measurable amount of time
to reach you from the lightning flash. This delay is approximately three seconds for
every kilometer, or five seconds for every mile. So how does this apply to Terraria? Well, the
observant among you might notice that thunder in Terraria does have a delay to it relative
to the lightning strike. It's a short delay, but it is there, and it is measurable.
This means we can actually calculate how far away the related lightning strike should
be from the player, even if we can't see it. For example, this thunderclap takes 1.42 seconds
to appear after the lightning strike, meaning the strike took place around half a kilometer away.
However, that's just one instance. Overall, the delay between thunder and lighting
is random, so if you want to find out the total range of lightning distances,
you'll need to look within the code. If you look in the method NewLightning(), you'll
notice that the thunder delay timer ranges between 1 and 120 ticks, or 0.016 and 2 seconds.
When this timer hits zero, it'll play one of seven random thunder noises, which is what you hear. And
on top of that, some of these noises themselves are also delayed. For example, while Thunder_5
starts immediately, with no delay, Thunder_2 has a full 3/4-second delay before it begins.
This adds a full 0.75 seconds to the longest possible delay, meaning the actual
lightning-thunder delay in Terraria actually ranges between 0.016 and 2.75 seconds.
The average thunder delay is around 0.85 seconds. So, now that we know that - how
does it translate to distance? Well, let's start with the longest. 2.75 seconds
at the speed of sound is about 935 meters - just shy of a kilometer. That's actually relatively
close, and it's just about the distance from spawn to the Dungeon on a small world.
On the other hand, the shortest one is actually comically short. A 0.016 second delay
- or one tick - corresponds to a distance of about five meters. Yeah. Rendered on the
screen, it would be roughly here. Quite close - but the Terrarian'll probably be fine.
Unfortunately, lightning isn't rendered in Terraria, so you'll never get to see
it, but it's funny to think about. So, that's it for this short video. It's
interesting to dissect such a benign and obscure mechanic sometimes - hell, I even
forgot this lightning thing existed for months because I left the config toggle off
after this video. Still, I think these little details in Terraria 1.4 is what makes it
feel so much more alive than 1.3 ever did.