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.)
(Cleaned up. (However, I'm going to test this to straighten out some question marks.))
Line 1: Line 1:
{{pov}}{{cleanup}}
'''Note:''' ''Somewhat still under construction today, but you can start adding to it now anyway.''
'''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]]
[[image:Lightning_test_01_screenshot0003.jpg|thumb|400px]]
Line 6: Line 5:
This is a tutorial for adding a lightning storm to a map.
This is a tutorial for adding a lightning storm to a map.


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:
The custom made lightning sprites (''lightning.vmt'' and ''lightningglow.vmt'') seen to the right and used in this tutorial, 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
* bluelight1
Line 20: Line 19:




==Setting up the sprites==
==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.
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.)
1. Place 2 [[env_sprite]]s about 2-10 units away from each other. (Make sure that one sprite is in front of the other.)
# Select the one closest to the skycamera entity.
# 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.)
# Set its ''Scale'' to ''7''.
# Make sure ''Render Mode'' is ''additive''.
# 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.
2. Select the sprite closest to the [[sky_camera]] entity, and change it's properties. This tutorial example will set the values as follows:
# Type a name (like ''lightning1'') in its ''Name'' field.
{{entity-kvalue-start|[[env_sprite]]}}
# Change the ''Sprite Name'' to the name of the lightning sprite to use. (''materials/sprites/lightning.vmt'')
{{entity-kvalue|Name|lightning1glow| The name of the glow sprite.}}
# Make sure the ''Render Mode'' is ''Additive''
{{entity-kvalue|Sprite Name|materials/sprites/lightningglow.vmt|The sprite to use for the lightning glow.}}
# Make sure that the ''FX Amount'' is ''255''.
{{entity-kvalue|Scale|7|}}
# Change the ''Scale'' to ''.75''.
{{entity-kvalue|Render Mode|Additive|}}
{{entity-kvalue|FX Amount|50|}}
{{entity-kvalue-end}}


==Timing between strikes==


Place a logic_timer in the map, preferably somewhere near your sprites.
3. Open the properties of the other sprite, and set them. 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|Sprite Name|materials/sprites/lightning.vmt|The sprite to use for the lightning.}}
{{entity-kvalue|Scale|.75|}}
{{entity-kvalue|Render Mode|Additive|}}
{{entity-kvalue|FX Amount|255|}}
{{entity-kvalue-end}}
 
 
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:
{{entity-kvalue-start|[[ambient_generic]]}}
{{entity-kvalue|Name|thunder1|The name of the thunder.}}
{{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.}}
{{entity-kvalue|Min Random Interval|1|}}
{{entity-kvalue|Max Random Interval|10|}}
{{entity-kvalue|Refire Interval|0.35|}}
{{entity-kvalue-end}}
 
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:
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|1|}}
# Set ''Refire Interval'' to ''0.35''.
{{entity-kvalue|Max Random Interval|10|}}
# Click on the ''Outputs'' tab and add some things to make it look like this:
{{entity-kvalue|Refire Interval|0.35|}}
{{entity-kvalue-end}}
 
 
2. Click on the ''Outputs'' tab and create the follow outputs:
{{entity-output-start}}
{{entity-output||OnTimerHigh|lightning1glow|ToggleSprite||0.00|No|}}
{{entity-output||OnTimerHigh|lightning1|ToggleSprite||0.00|No|}}
{{entity-output||OnTimerLow|lightning1|ToggleSprite||0.00|No|}}
{{entity-output||OnTimerLow|lightning1glow|ToggleSprite||0.00|No|}}
{{entity-output||OnTimerLow|thunder1|PlaySound||<delay>|No|<delay> is a value reflecting how far away the lightning struck.}}
{{entity-output-end}}


http://img162.imageshack.us/img162/6269/step202af5.jpg


(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!)
3. Set its only flag:
Once you're done that click on the flags tab and make sure the only flag that showing is checked!
{{entity-flag-start}}
{{entity-flag|Oscillator (alternates between OnTimerHigh and OnTimerLow outputs)|on|}}
{{entity-flag-end}}


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


==Adding thunder==
4. Save it and test the map.


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. (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:
{{entity-kvalue-start|[[func_rotating]]}}
{{entity-kvalue|Name|lightningrotator|The name of the rotator.}}
{{entity-kvalue|max rotating speed|3|}}
{{entity-kvalue|friction|20|}}
{{entity-kvalue-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. Add a [[logic_auto]] to the map (I'm not sure if this is needed or not...)
 
4. In its ''Outputs'' tab add this:
{{entity-output-start}}
{{entity-output||OnMapSpawn|lightningrotator|Start||0.00|Yes|}}
{{entity-output-end}}
 
 
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:
{{entity-flag-start}}
{{entity-flag|Play everywhere|on|}}
{{entity-flag-end}}
 


# Create a small brush textured with the ''invisible'' tool texture.
6. Save and test the map.
# 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.

Revision as of 09:10, 19 August 2006

Note: Somewhat still under construction today, but you can start adding to it now anyway.

Lightning test 01 screenshot0003.jpg

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
Entity-output-icon.png OnTimerHigh lightning1glow ToggleSprite 0.00 No
Entity-output-icon.png OnTimerHigh lightning1 ToggleSprite 0.00 No
Entity-output-icon.png OnTimerLow lightning1 ToggleSprite 0.00 No
Entity-output-icon.png OnTimerLow lightning1glow ToggleSprite 0.00 No
Entity-output-icon.png OnTimerLow thunder1 PlaySound <delay> No <delay> is a value reflecting how far away the lightning struck.


3. Set its only flag:

Flag
Checkbox-on.png 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
Entity-output-icon.png 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
Checkbox-on.png Play everywhere


6. Save and test the map.