nmdist-log

Starting NPC movement

This weekend I started implementing NPC movement. That involved hooking up the trigger_once and scripted_sequence entity types, as well as building the foundation for a “path animation” system in the engine.

As I mentioned previously, I’m using the Recast and Detour libraries for building navigation meshes and path finding. In that post, I had rigged up a way to visualize the path between two entities by plotting the points along the path. Now I needed a way to make an entity move along that path. Instead of rigging up yet another console command, I decided to implement the trigger_once and scripted_sequence entity types. On the level c1a0, there’s a trigger entity that causes a scientist to round the corner and walk past you into the lobby.

A view of the trigger entity that causes a scientist to begin moving.

By leveraging some of the same code that I use for level transitions, I’m able to detect when the player intersects this trigger. As you can see from the screenshot, the trigger specifies a target. In this case, that target is a scripted_sequence which describes how and where to move the scientist that is standing around the corner further down the hallway. Right now, I only support scripted_sequence entities, but Half-Life actually triggers a few different entity types from a trigger:

Entity type Occurrences
multi_manager 216
scripted_sequence 90
ambient_generic 68
monstermaker 66
func_breakable 56
scripted_sentence 49
func_door_rotating 39
func_door 38
env_message 32
env_sprite 27
light 26
trigger_relay 18
multisource 13
env_beam 11
env_shake 11
env_shooter 9
player_loadsaved 9
gibshooter 8
env_explosion 6
env_render 5
func_train 5
aiscripted_sequence 4
trigger_cdaudio 4
trigger_hurt 4
func_tank 2
func_tracktrain 2
monster_apache 2
env_fade 1
func_wall 1
monster_ichthyosaur 1
path_track 1
target_cdaudio 1
trigger_push 1

Implementing the rest of these will be a problem for future me.

After I was able to determine when, where, and what entity to move, I rigged together a foundation for path animations. It leverages the existing animation system I have for animating doors, and the path animation system essentially allows me to string together offset animations. This will probably come in handy when I implement trains. At some point, this system will have to be more robust, as it doesn’t account for obstacles an NPC might encounter during its journey. But it will do for now.

After stringing that all together, I was able to see the scientist move down the hall! Keep in mind that I’m not playing their walk animation, and the speed is currently hard coded. Apparently the speed of an NPC is tied to their animation, which I haven’t implemented yet. Additionally, the rotation of the NPC gets clobbered by the offset update.

Apart from the issues I’ve already outlined, you’ll notice that there’s something not quite right about the way the scientist moves at the beginning and end of the animation. I think that’s because of the extra points on the path when rounding corners, but I’ll need to debug it to know for sure.

That’s it for this week!