WiseGateLock: Locked Gate

From Valve Developer Community
Jump to: navigation, search


This tutorial was originally created by wisemx. It was originally posted on SDKnuts.net.

Introduction

In this project:

  1. Player sees a gate with a padlock on it.
  2. The gate can’t be opened.
  3. Player breaks lock with crowbar.
  4. Lock falls to ground, gate can be pushed open.

There are two sample files in the project download at the bottom of this page.

In the first one a phys_hinge is used for the lock, so it can move on the latch.

In the second example everything is the same except there is no phys_hinge. The lock has motion disabled until it’s broken by the player. The first example is a little more difficult to create while the second example is rather simple. I’m not sure the first example is even needed but I’ve included it so you have that option. An additional problem with the first example, with the phys_hinge, is while the HL2 Source engine physics are exceptional they can create problems with objects like this. Compile both examples and run them, decide for yourself which is best for your needs.

Creation

There are multiple methods that can be used for the actual gate. In this project the gate is a func_door_rotating entirely textured with tools\toolsnodraw. This allows the actual gate prop to be parented to it. The visible gate is a prop_dynamic with the model models\props_wasteland\exterior_fence003b.mdl. This allows for a quick and easy door you don’t have to configure hinges for. If you browse through the many door tutorials from SDKNuts you’ll find several of them use hinges, some are also prop entities, there are advantages to each method and this gives you a lot of flexibility.

WiseGateLock overview.png

In the image to the left, from the 3D viewport in Hammer, you can see the func_door_rotating textured with nodraw and the only the handle is showing for the prop_dynamic parented to it. The purple cube is the phys_hinge for the padlock. The padlock is a prop_physics using the model models\props_wasteland\prison_padlock001a.mdl. The latch for this project is func_brush. This is something that you can be creative with. The properties for this func_brush make it not-solid, it’s for appearance only. With an output from the padlock when it breaks the latch will disappear. You could also make the latch a func_physbox so you can break it into pieces. By making it func_brush we can easily eliminate any problems with physics. For an added effect I’ve included an env_spark to spark once when the padlock breaks. The rest of the fencing in this project is all prop_static.

You have a lot of options with your gate, the func_door_rotating. In the flags for this one I’ve specified that it starts locked and can be opened by touch. Once the gate is fully opened I’m using an output back to itself to Lock it in the opened position. It will appear to the player that they pushed it open once the lock was broken.

As you can see below most of the work is done by the padlock. The outputs shown here are those from the prop_physics padlock.

WiseGateLock padlock outputs a.png

These are the outputs from the second example, without the phys_hinge.

WiseGateLock padlock outputs b.png

An additional flag is checked for the second example, Motion Disabled. This will hold it in place until it receives damage from the player’s crowbar. For the rest of the properties used in each project open them in Hammer and have a look. Make some changes and come up with the effect that’s right for your project.

See also