Creating Breakable Lamps

Tutorial collection, comprehensive listings on main site.

Creating Breakable Lamps

Postby Tutorial on Sun Jan 13, 2008 11:59 pm

category
General Half-Life 2/Effects

description
Shoot out a light and bask the player in darkness, complete with a point_spotlight as well.

keywords
light, breakable, func_breakable, light_spot, point_spotlight, shoot.

I've been browsing around this site unregistered for quite a while now and I decided it's time for me to give something in return.

I was looking around here and on a couple of other sites with Hammer tuts and I never managed to find a tutorial about breakable lights. If you for example use a prop_static for your light model and a light_spot for the light itself you can't just make the light turn of when the model is shot at (as far as I know). So after playing around a bit I found a way that works and here it is:

1. Create a prop_static which will be the lamp itself. Then go into the props properties and choose a model for it. My lamp will be lampfixture01a as it is a lamp that is easy to stick up on walls.

Image

2. Next step is to create the light source. I always use light_spot after reading SgtJman's Advanced Lighting tutorial (Which I will borrow some other tips from too). There are two important things to think about when creating the light.
First of all you don't want it to actually be inside the model. It actually doesn't matter if it's a couple of units away from it as it only project a light on the nearest surfaces and you can trim it to look good using the properties later.
The second thing is that you want the light to point in the right direction. Not all lamp models have a straight -90 degree pitch. The one I chose for example has a pitch closer to -75 degrees (-76.5 looks the best according to me). This is quite important if you want your light effects to look good in your map.

Image

3. Next up is the light beam. This is created with the help of point_spotlight.
Same thing here as for the light source, you don't want it to be inside the model and you need to adjust the pitch. Although since this is the beam of light it has to be as close to the prop as possible. I'm not sure how close it can be, so you will have to test that. This is because if it's too far away the beam is going to start in the middle of the air and not at the lamp like we want it to.

Image

4. From here there are various ways to improve the light, such as altering colors, brightness and adding sprites, to make it look more realistic but as this tutorial is about breaking the light I won't cover that. Instead I recommend the same SgtJman's tutorial.

5. So now on to the fun parts: Destroying the light.
For this to work we need some sort of trigger to turn all the lights off. As the normal trigger_once only triggers on being touched by a player (Once again, only as far as I know) I decided to be a little more creative.
Create a brush and place it in front of the glass part of the lamp. Make sure that the whole brush uses the Nodraw texture so that it won't be visible. Once you have lined it up good press Ctrl+T (Tie to Entity). Select the entity func_breakable and press apply.

Preview (Clicky clicky):
Image

6. The reason I didn't say anything about changing any properties earlier is that I find it a lot easier if you do it all at once, so that you don't have previous changes that you don't remember making screwing it up for you (Believe me, it has happened). So now it's time for the changing.
First thing you need to do is name all parts of this except the prop. I named them as follows to make it easy:
light_spot Name: Light01_Light
point_spotlight Name: Light01_Spotlight
funk_breakable Name: Light01_Trigger

7. As lamps also has a protective cover of glass which breaks when you shoot at it you can add more realism by making the funk_breakable a bit of glass which produces a few gibs.
To do this you need to make sure that the following conditions are met:
Material Type: Glass
Prop Data: Glass.Small
Now I don't know if this is a bug in my Hammer or something, but when I set Strength to 0 the glass breaks really easy even though it says in the tooltip "0 means don't break". Either way, set the Strength a low value so that the glass will break easily.

8. The final thing you need to do is set up the triggers to turn the light off when the glass is broken. This is done through a series of outputs from the funk_breakable. Here is the list:

My output named: OnBreak
Target entities named: [Name of the light_spot]
Via this input: TurnOff
Fire once only: [x]

My output named: OnBreak
Target entities named: [Name of the point_spotlight]
Via this input: LightOff
Fire once only: [x]

This one is optional if you happen to have a sprite, as they don't seem to have a "TurnOff" type of input.
My output named: OnBreak
Target entities named: [Name of the Sprite]
Via this input: Kill
Fire once only: [x]

Once you are done, your outputs should look like this:
Image

That should cover it all, now save and compile your map and boot up whatever game you made it for to test it. If any of the lights aren't appearing then try moving them a bit further away from the lamp model, as they are probably inside.


This is what it looks like:
Image
Image

-Avalyst
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Re: Creating Breakable Lamps

Postby Avalyst on Mon Jan 14, 2008 11:16 am

Yay, cheers for positing, Blink :D
User avatar
Avalyst
Member
Member
 
Joined: Fri Jan 04, 2008 2:25 pm
Location: Sweden

Re: Creating Breakable Lamps

Postby stoopdapoop on Tue Jan 15, 2008 4:45 pm

Looks good to me, simple, sweet and useful to those who would need it.

what would be useful is if you could switch cubemaps or something after you shot out the light, but I don't know if that's even possible. That way you don't get glowing guns.

I guess you could draw the cubemap while the light was off though, but the reflections would be lame.
User avatar
stoopdapoop
Veteran
Veteran
 
Joined: Sun Aug 21, 2005 2:14 am
Location: Ann Arbor, MI

Re: Creating Breakable Lamps

Postby nub on Thu Jan 17, 2008 10:40 pm

Yeah it's the one thing I really hate about Source--no true dynamic lighting. Although it's a really difficult thing to code into a game engine.

The only time breakable lights are somewhat decent is in an SP map I guess. But there is a better way to do this:

It's really the same but you can use a prop_dynamic(_override) with a light fixture that has a skin showing that it's on and one that projects it as off. You can make it so once the func_breakable is broken, the skin swaps from the "on" skin to the "off" skin. I used many light fixtures like that when making zm_concrete.
User avatar
nub
Veteran
Veteran
 
Joined: Tue Nov 15, 2005 1:11 am
Location: Charlotte, NC, US

Re: Creating Breakable Lamps

Postby Avalyst on Thu Jan 31, 2008 6:58 pm

That was pretty much what I was looking for in the beginning. But since I didn't find that I chose to make it this way.

But doesn't prop_dynamics have physics? Might be annoying and unnecessary with a lamp like mine in the tutorial.
User avatar
Avalyst
Member
Member
 
Joined: Fri Jan 04, 2008 2:25 pm
Location: Sweden

Re: Creating Breakable Lamps

Postby Generalvivi on Thu Jan 31, 2008 7:16 pm

good tutorial.
Generalvivi
Irrational Games
 
Joined: Fri Feb 18, 2005 1:41 am
Location: Boston

Re: Creating Breakable Lamps

Postby thefilthelement on Thu Jan 31, 2008 9:01 pm

Oh god, those blue windows make my eyes bleed.
thefilthelement
Regular
Regular
 
Joined: Mon Jan 16, 2006 11:39 am

Re: Creating Breakable Lamps

Postby Avalyst on Sun Feb 03, 2008 12:33 pm

Haha, two reasons for them:
1. Blue is a relaxing color for the eyes, and I want to have me eyesight left for a few years to come even though I spend a lot of time at my comp.
2. The Old school windows theme is performance economic and my comp isn't top of the line =)
User avatar
Avalyst
Member
Member
 
Joined: Fri Jan 04, 2008 2:25 pm
Location: Sweden

Re: Creating Breakable Lamps

Postby Blink on Thu Feb 07, 2008 9:37 pm

That particular blue is far from relaxing.. :P
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Re: Creating Breakable Lamps

Postby krainert on Mon Apr 21, 2008 6:59 am

Sweet.
User avatar
krainert
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Thu Dec 20, 2007 2:57 pm
Location: Denmark

Return to Tutorials

Who is online

Users browsing this forum: No registered users