Falling headcrab tutorial

From Valve Developer Community
Jump to: navigation, search

Browsing the model animations of the npc_headcrab, you may have spotted the falling animation ceiling_fall and landing animation ceiling_land and asked yourself why headcrabs hanging from the ceiling has elegant falling animations while headcrabs otherwise don't.

The purpose of this tutorial is to primarily use a scripted sequence to simulate a scripted fall that looks better. (Note that this is designed to be a scripted fall specific to a headcrab falling a certain distance to a certain destination, but you could probably make it general enough to encompass general NPCs, through the use of filters, through providing landing zones at each fall point, and through tying fallspeed controllers to any falling NPC.)

Basic setup

We will start by setting up an npc_headcrab on top of a simple platform, which we will trigger to break to that the headcrab falls down. This means we will make the platform a func_breakable. (For aestetics, you can set the Material Type keyvalue of the platform to match the material it is made of.) Name the platform "Crab platform".

Next we set up a trigger_once trigger to trigger the platforms with the simple output:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger Crab platform Break Yes

To get a good look of how an ordinary headcrab fall looks, we can compile and run the map now. (You can use a Block LOS tool texture if you want to prevent the headcrab from jumping off the platform from seeing you.)


Falling animation

Now it's time to add the scripted sequence, but first, every actor has to have a name, so name the npc_headcrab "Headcrab".

Now create the scripted_sequence anywhere in the map, and change the following keyvalues:

Class: scripted_sequence
Keyvalues Comments
Name Crab SS fall
Target NPC Headcrab
Action Animation ceiling_fall
Loop Action Animation? Yes
Move to Position No

Link it to the trigger_once like so:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger Crab SS fall BeginSequence Yes

If we compile, we'll see that the headcrab assumes the falling position and falls, but there's two problems: First of all it falls way too slow, and second or all it will not "land" once it reaches the floor.


Landing

We will fix the landing first, by creating a thin trigger_once at the landing zone, and giving it the following output:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger Crab SS fall CancelSequence Yes

(We won't need another sequence to play the landing animation because the falling animation will automatically play it while transitioning to the normal idle animation.)

We will also need to set the flag of the trigger to apply to the headcrab instead of the player client (which is default):

Flag
Checkbox-off.png Clients
Checkbox-on.png NPCs

(If there are other NPCs involved in this area, we would need to create a filter_activator_name to make the trigger specific to the headcrab named "Headcrab", to prevent the other NPCs from triggering this trigger prematurely.)


Falling speed

Now it's time to speed up the falling speed of the headcrab. We do this by parenting it to a moving entity, and letting it "carry" the headcrab downwards. We could parent it to a func_tracktrain that would travel to a path_track, but when it's only a matter of a single destination, we can use the simpler brush entity func_movelinear instead. (This entity is actually a door, that when opened is meant to "slide" a certain distance, but as long as it's invisible, nobody will notice.)

Create a func_movelinear with the following keyvalues:

Class: func_movelinear
Keyvalues Comments
Name Headcrab fallspeed controller
Render Mode Dont Render
Disable Receiving Shadows Yes
Move Direction (Pitch Yaw Roll) 90 0 0 You can simply choose "Down" from the dropdown menu.
Speed 100 This is a decent falling speed. Remember that this speed is added to the basic scripted falling speed.
Move Distance <distance> This should be set to at least the distance from the headcrabs location to the location of the landing trigger.

We also need to set its Not Solid flag:

Flag
Checkbox-on.png Not Solid

We also need to parent the controller to the npc_headcrab:

Class: npc_headcrab
Keyvalues Comments
Parent Headcrab fallspeed controller

Then we need to trigger it in the first trigger_once:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger Headcrab fallspeed controller Open Yes


Finally, we need to detach the headcrab from the controller once it has landed (so that it can move freely) so we add the following line to the landing zone trigger_once:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger Headcrab ClearParent Yes


See also