Lightning: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Cleaned up the article a bit. Will continue after I'm finished *crying* over its previous state.)
m (→‎Custom lightning sprites: Unicodifying, replaced: [[image: → [[File:)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{pov}}{{cleanup}}
This is a tutorial for adding a lightning storm to a map.
'''Note:''' ''This article is under construction today. I'm just making a temp save and taking a breather.''


[[image:Lightning_test_01_screenshot0003.jpg|thumb|400px]]
It is assumed that the reader knows how to create a [[3D Skybox|3D skybox]] before reading this tutorial.


This is a tutorial for adding a lightning storm to a map.
==Custom lightning sprites==
 
[[File:Lightning_test_01_screenshot0003.jpg|thumb|200px|Custom made lightning sprites.]]
 
Here are all the sprites of (normal) lightning bolts in the HL2 SDK:


It will use custom made lightning sprites (''lightning.vmt'' and ''lightningglow.vmt'') which can be downloaded [http://files.filefront.com/Lightning_Tutorial_Files/;5261042;;/fileinfo.html here] (along with an example map). However, the following sprites already included in the SDK can simulate lightning suffciently too:
* bluelight1.vmt
* lgtning.vmt
* lgtning_noz.vmt
* physcannon_bluelight1b.vmt


* bluelight1
You can also download some custom made lightning sprites (seen in the screenshot to the right, but not required for this tutorial). Just create a new ''sprites'' folder in the ''hl2/materials/'' folder, unpack the custom sprite files into it, and refresh the SDK content, before running the example map.
* lgtning
{{clr}}
* lgtning_noz
* physcannon_bluelight1b


It is assumed that the reader knows how to create a [[3D Skybox|3D skybox]] before reading this tutorial.
==Setting up==


1. 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.


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.  
2. Create two [[env_sprite]]s and place them next to each other.


3. Select the one of these sprite entities, and open it's properties. This sprite will be the actual lighting bolt. This tutorial example will set the values as follows:
{{entity-kvalue-start|[[env_sprite]]}}
{{entity-kvalue|Name|lightning1| The name of the lightning sprite.}}
{{entity-kvalue|Render FX|Faster Strobe|}}
{{entity-kvalue|Render Mode|Additive|}}
{{entity-kvalue|FX Amount (0-255)|200|}}
{{entity-kvalue|Sprite Name|sprites/lgtning.vmt|The sprite to use for the lightning. (Don't forget to add ".vmt".)}}
{{entity-kvalue|Scale|2|}}
{{entity-kvalue-end}}




==Setting up the sprites==
4. Open the properties of the other sprite. This sprite will be the background glow of the lightning, so that it will light up the sky. This tutorial example will set the values as follows:
{{entity-kvalue-start|[[env_sprite]]}}
{{entity-kvalue|Name|lightning1glow| The name of the glow sprite.}}
{{entity-kvalue|Render FX|Faster Strobe|}}
{{entity-kvalue|Render Mode|Additive|}}
{{entity-kvalue|FX Amount (0-255)|25|}}
{{entity-kvalue|Sprite Name|sprites/light_glow02.vmt|The sprite to use for the lightning glow. (Don't forget to add ".vmt".)}}
{{entity-kvalue|Scale|7|}}
{{entity-kvalue-end}}


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.


# Place 2 [[env_sprite]]s about 2-10 units away from each other. (Make sure ones in front of the other.)
5. 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:
# Select the one closest to the skycamera entity.
{{entity-kvalue-start|[[ambient_generic]]}}
# In the Sprite Name box write the name of the glow sprite to use for the lightning glow. (The pictures will use the custom ''materials/sprites/lightningglow.vmt'' sprite.)
{{entity-kvalue|Name|thunder1|The name of the thunder.}}
# Set its ''Scale'' to ''7''.
{{entity-kvalue|Sound Name|k_lab.teleport_post_thunder|You can find four more good thunder sounds if you search for ''thunder'' in the sound browser.}}
# Make sure ''Render Mode'' is ''additive''.
{{entity-kvalue-end}}
# Make sure that the ''FX Amount'' is ''50''.
# Also change the ''Name'' to ''lightning1glow''.
# After that click ''Apply'' and then ''Cancel''.


Open the properties of the other sprite.
# Type a name (like ''lightning1'') in its ''Name'' field.
# Change the ''Sprite Name'' to the name of the lightning sprite to use. (''materials/sprites/lightning.vmt'')
# Make sure the ''Render Mode'' is ''Additive''
# Make sure that the ''FX Amount'' is ''255''.
# Change the ''Scale'' to ''.75''.


==Timing between strikes==
==Timing it==


Place a logic_timer in the map, preferably somewhere near your sprites.
1. Place a logic_timer in the map, preferably somewhere near your sprites.
Open its properties and make the following alterations:
Open its properties and make the following alterations:
# Name it. (''lightning1timer'')
{{entity-kvalue-start|[[logic_timer]]}}
# Make sure ''Use Random Time'' is set to ''yes''.
{{entity-kvalue|Name|lightning1timer|The name of the timer.}}
# Make sure ''Min Random Interval'' is set to ''1''.
{{entity-kvalue|Use Random Time|Yes|The lightning will strike at random intervals.}}
# Make sure ''Max Random Interval'' is set to ''10''.
{{entity-kvalue|Min Random Interval|5|Minimum time between strikes. Set it lower than this and the thunder will cut itself.}}
# Set ''Refire Interval'' to ''0.35''.
{{entity-kvalue|Max Random Interval|60|Maximum time between strikes.}}
# Click on the ''Outputs'' tab and add some things to make it look like this:
{{entity-kvalue-end}}
 


http://img162.imageshack.us/img162/6269/step202af5.jpg
2. Click on the ''Outputs'' tab and create the follow outputs:
{{entity-output-start}}
{{entity-output||OnTimer|lightning1glow|ShowSprite||0.00|No|}}
{{entity-output||OnTimer|lightning1|ShowSprite||0.00|No|}}
{{entity-output||OnTimer|lightning1glow|HideSprite||0.50|No|}}
{{entity-output||OnTimer|lightning1|HideSprite||0.50|No|}}
{{entity-output||OnTimer|thunder1|PlaySound||<delay>|No|<delay> is a value reflecting how far away the lightning struck.}}
{{entity-output-end}}


(Important Note: The example shows the number 2 but in this tutorial number 1 is used so just replace the 2 with 1. Also the Last line is an optional part of this tutorial!)
Once you're done that click on the flags tab and make sure the only flag that showing is checked!


Done. Save it and test it out. The steps below are optional.
3. Save it and test the map.


==Adding thunder==
4. So far only one lightning bolt has been created. To create more of them, 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).


To add some thunder sounds it is recommended to use a soundscape (which is not covered by thia tutorial), but a quicker way is to place an [[ambient_generic]] somewhere in the map - not in the 3D skybox - and change its name to ''Thunder.01'', change its sound name to ''k_lab.teleport_post_thunder'' or another good thunder sound. Then go back to the logic_timer and add
"OnTimerLow"
"Thunder.02"
"PlaySound"
to the output tab. You can also set a delay that will reflect on how far away that the lighting is.


==Randomized lightning==
==Randomized lightning==


To prevent the lightning from hitting the same spot twice, you can make the sprites rotate around the skybox. (This doesn't actually show the lightning strikes moving.)
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. (The lightning will fortunately strike so fast that its movement while visible will barely be noticeable.)
 
1. Create a small brush textured with the ''invisible'' tool texture, turn it into a ''func_rotating'' entity, and change its properties as follows:
{{entity-kvalue-start|[[func_rotating]]}}
{{entity-kvalue|Name|lightningrotator|The name of the rotator.}}
{{entity-kvalue|max rotating speed|3|}}
{{entity-kvalue-end}}
 
Also set the following flag:
{{entity-flag-start}}
{{entity-flag|Start ON|on|}}
{{entity-flag-end}}
 
 
2. Go back to your two sprites and set their ''Parent'' field:
{{entity-kvalue-start|[[env_sprite]]}}
{{entity-kvalue|Parent|lightningrotator|The name of the rotator.}}
{{entity-kvalue-end}}
 
 
3. 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.
 
Just open the ambient_generic entity and set the following flag:
{{entity-flag-start}}
{{entity-flag|Play everywhere|on|}}
{{entity-flag-end}}
 
 
4. Save and test the map.
 
== See also==
* [[Skybox]]


# Create a small brush textured with the ''invisible'' tool texture.
[[Category:Level Design]]
# Turn it into a ''func_rotating'' entity.
# Call it ''lightningrotator''
# Change the ''max rotating speed'' to ''3''.
# Change the ''friction'' to ''20''.
# Click ''Apply'' and close its window.
# Go back to your two sprites and change their parent to ''lightningrotator''.
# Add a [[logic_auto]] to the map (Not sure if this is needed or not...)
# In its ''Outputs'' tab add this:
"OnMapSpawn"
"lightningrotator"
"Start"
# Save and test the map.

Latest revision as of 10:53, 8 January 2024

This is a tutorial for adding a lightning storm to a map.

It is assumed that the reader knows how to create a 3D skybox before reading this tutorial.

Custom lightning sprites

Custom made lightning sprites.

Here are all the sprites of (normal) lightning bolts in the HL2 SDK:

  • bluelight1.vmt
  • lgtning.vmt
  • lgtning_noz.vmt
  • physcannon_bluelight1b.vmt

You can also download some custom made lightning sprites (seen in the screenshot to the right, but not required for this tutorial). Just create a new sprites folder in the hl2/materials/ folder, unpack the custom sprite files into it, and refresh the SDK content, before running the example map.

Setting up

1. 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.

2. Create two env_sprites and place them next to each other.

3. Select the one of these sprite entities, and open it's properties. This sprite will be the actual lighting bolt. This tutorial example will set the values as follows:

Class: env_sprite
Keyvalues Comments
Name lightning1 The name of the lightning sprite.
Render FX Faster Strobe
Render Mode Additive
FX Amount (0-255) 200
Sprite Name sprites/lgtning.vmt The sprite to use for the lightning. (Don't forget to add ".vmt".)
Scale 2


4. Open the properties of the other sprite. This sprite will be the background glow of the lightning, so that it will light up the sky. This tutorial example will set the values as follows:

Class: env_sprite
Keyvalues Comments
Name lightning1glow The name of the glow sprite.
Render FX Faster Strobe
Render Mode Additive
FX Amount (0-255) 25
Sprite Name sprites/light_glow02.vmt The sprite to use for the lightning glow. (Don't forget to add ".vmt".)
Scale 7


5. 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.


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 5 Minimum time between strikes. Set it lower than this and the thunder will cut itself.
Max Random Interval 60 Maximum time between strikes.


2. Click on the Outputs tab and create the follow outputs:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTimer lightning1glow ShowSprite 0.00 No
Entity-output-icon.png OnTimer lightning1 ShowSprite 0.00 No
Entity-output-icon.png OnTimer lightning1glow HideSprite 0.50 No
Entity-output-icon.png OnTimer lightning1 HideSprite 0.50 No
Entity-output-icon.png OnTimer thunder1 PlaySound <delay> No <delay> is a value reflecting how far away the lightning struck.


3. Save it and test the map.

4. So far only one lightning bolt has been created. To create more of them, 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).


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. (The lightning will fortunately strike so fast that its movement while visible will barely be noticeable.)

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

Also set the following flag:

Flag
Checkbox-on.png Start ON


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. 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.

Just open the ambient_generic entity and set the following flag:

Flag
Checkbox-on.png Play everywhere


4. Save and test the map.

See also