Lightning
Note: Somewhat still under construction today, but you can start adding to it now anyway.
This is a tutorial for adding a lightning storm to a map.
The custom made lightning sprites (lightning.vmt and lightningglow.vmt) seen to the right and used in this tutorial, can be downloaded here (along with an example map). However, the following sprites already included in the SDK can simulate lightning suffciently too:
- bluelight1
- lgtning
- lgtning_noz
- physcannon_bluelight1b
It is assumed that the reader knows how to create a 3D skybox before reading this tutorial.
This setup will make the lightning automatically start on. You will have to do some random triggers if you want it to only be on at a certain part of the map.
Setting up
Unless lightning is intended to be close enough to strike within the playing area, create the 3D skybox that will house the lightning storm. Make sure that its fog is disabled.
1. Place 2 env_sprites about 2-10 units away from each other. (Make sure that one sprite is in front of the other.)
2. Select the sprite closest to the sky_camera entity, and change it's properties. This tutorial example will set the values as follows:
Class: env_sprite | ||
Keyvalues | Comments | |
Name | lightning1glow | The name of the glow sprite. |
Sprite Name | materials/sprites/lightningglow.vmt | The sprite to use for the lightning glow. |
Scale | 7 | |
Render Mode | Additive | |
FX Amount | 50 | |
3. Open the properties of the other sprite, and set them. This tutorial example will set the values as follows:
Class: env_sprite | ||
Keyvalues | Comments | |
Name | lightning1 | The name of the lightning sprite. |
Sprite Name | materials/sprites/lightning.vmt | The sprite to use for the lightning. |
Scale | .75 | |
Render Mode | Additive | |
FX Amount | 255 | |
4. To add some thunder sounds it is recommended to use a soundscape (which is not covered by this tutorial), but a quicker way is to place an ambient_generic entity somewhere in the map in the direction of the lightning strike (Do not place it in the skybox.) and change its properties as follows:
Class: ambient_generic | ||
Keyvalues | Comments | |
Name | thunder1 | The name of the thunder. |
Sound Name | k_lab.teleport_post_thunder | You can find four more good thunder sounds if you search for thunder in the sound browser. |
Min Random Interval | 1 | |
Max Random Interval | 10 | |
Refire Interval | 0.35 | |
5. So far only one lightning bolt has been created. To create more, simply place a number of copies of this created set around in the skybox, and name them in sequential order (lightning2, lightning3, lightning4, and so on).
Timing it
1. Place a logic_timer in the map, preferably somewhere near your sprites. Open its properties and make the following alterations:
Class: logic_timer | ||
Keyvalues | Comments | |
Name | lightning1timer | The name of the timer. |
Use Random Time | Yes | The lightning will strike at random intervals. |
Min Random Interval | 1 | |
Max Random Interval | 10 | |
Refire Interval | 0.35 | |
2. Click on the Outputs tab and create the follow outputs:
My output | Target entity | Target input | Parameter | Delay | Only once | Comments | ||
![]() |
OnTimerHigh | lightning1glow | ToggleSprite | 0.00 | No | |||
![]() |
OnTimerHigh | lightning1 | ToggleSprite | 0.00 | No | |||
![]() |
OnTimerLow | lightning1 | ToggleSprite | 0.00 | No | |||
![]() |
OnTimerLow | lightning1glow | ToggleSprite | 0.00 | No | |||
![]() |
OnTimerLow | thunder1 | PlaySound | <delay> | No | <delay> is a value reflecting how far away the lightning struck. | ||
3. Set its only flag:
Flag | ||||
![]() |
Oscillator (alternates between OnTimerHigh and OnTimerLow outputs) | |||
4. Save it and test the map.
Randomized lightning
To prevent the lightning from unrealistically striking at the same spot over and over again, you can also make the sprites rotate around the skybox. (This will fortunately not show the lightning strikes moving.)
1. Create a small brush textured with the invisible tool texture, turn it into a func_rotating entity, and change its properties as follows:
Class: func_rotating | ||
Keyvalues | Comments | |
Name | lightningrotator | The name of the rotator. |
max rotating speed | 3 | |
friction | 20 | |
2. Go back to your two sprites and set their Parent field:
Class: env_sprite | ||
Keyvalues | Comments | |
Parent | lightningrotator | The name of the rotator. |
3. Add a logic_auto to the map (I'm not sure if this is needed or not...)
4. In its Outputs tab add this:
My output | Target entity | Target input | Parameter | Delay | Only once | Comments | ||
![]() |
OnMapSpawn | lightningrotator | Start | 0.00 | Yes | |||
5. You could make another rotator within the actual map, to match the direction of the thunder with the lightning flashes, but using a single stationary ambient_generic for all the bolts won't make that much of a difference.
Open the ambient_generic entity and set the following flag:
Flag | ||||
![]() |
Play everywhere | |||
6. Save and test the map.