Adding a door is a relatively simple thing that can go horribly wrong if not done properly. First, add a large hallway off to the side of your map. Then, make a doorframe that's at least 5 grid units thick (and an odd number - 7, 9, 15, etc) just inside your new corridor. It should look something like this:
You can make whatever type of fancy doorframe you like (or even none at all). You are making a doorframe like this here in order to illustrate an important point later. Now, build the door itself. For the sake of illustration, we will be making a double sided door. Make it fit perfectly into your doorframe (make sure the door doesn't z-fight with the frame!). I ended up with this (I used bespin/door_new for the front and back of the door and bespin/u_metalgreenrib for the inside track (remember that the player will be able to see this when the door is open, so don't caulk it!)
Next, select the left side of the door and make it into a func_door (Select it and right click in the 2D View; then select func_door from the func menu). Repeat for the right door. Now, since you want the doors to open at the same time, highlight BOTH doors and open up the Entity Property window (N Key). Add the key team and any value that you want. This value will be used to identify which func_doors open at the same time (Note: The doors can be clear across the map from each other - they don't need to necessarily touch). After this, deselect the doors and select just the left. Change your 2D View to the XY Top view. Now set the Angle for the door to open. For the left door, have the door move... left. (: For the right, right. Assign an angle to each door in the same way that you assign an angle to info_player_start. If you had a door you wanted to slide up or down, just hit the Up or Dn buttons instead. You should see arrows appear on each door in the 2D View. Next, there's nothing worse than a silent door, is there? To look up the soundsets you can use for doors, open up the sound/sound.txt file and do a text search for... well, the word "door." Add the key soundset and the value for the soundset you want. I will be using large_door for mine. You can also set the speed with which the door opens. The default (100) is rather fast, so I set mine down a tad to 85 (by setting a key of speed and a value of 85). Now if you compile and look at your map, you should notice/check two things. The first thing you should notice is that the door sticks out a few units when it's open. What if you didn't want it to stick out? Well, then you'd need to add the lip key with a value of how many grid units you want it to stick out. This can also be used to make a door switch between opening and closing two corridors (making the lip low enough (-40, -50, etc) to move all the way to another corridor. If you want the door lip to be 0, make sure that you cut your doorframe brush in such a way that the door has a place to go. If not, you will get z-fighting errors between the edge of the door and your doorframe. All you need to do is cut a hole in the center of the lower half of the door frame for the door to move into. Also note that for no lip, you will often need to set the lip to 2, not 0. And no, there's no real specific reason for this. In any case, without the door showing, it should look like this: Remember, you need to put textures wherever the player might look when the door is open or closed. The second thing you should check is a little less obvious. Remember how when we went over compiling and detail brushes, we talked about the VIS process only being blocked by structural brushes and nothing else? Since our doorframe is full of detail brushes and the door itself is technically an entity, nothing is blocked in this hallway! You can check yourself by compiling now and looking at the door with the command r_showtris 1 executed in the console. This will show all triangles being drawn by the engine at any given point.
Look at that waste of triangles! To fix it, we need to tell the VIS process to create a portal where there otherwise wouldn't normally be one. Make a brush the side of the entire doorframe and cover it in the system/areaportal shader. Then adjust it to fix entirely inside the door. This means if you made your original doorframe 5 units thick, the door would be 3 units thick, and the areaportal would be 1 unit thick.
Notice that now the rear brush isn't drawn. Further from that, if you had another room or even a large outdoor area beyond the hallway, you wouldn't see them either. Thus, always remember to have some sort of hallway (even if it's only a few grid units long) between rooms so that your areaportals block efficiently. That's all there is to doors! |
|