NPCs (a bloody fucking nightmare)

Share
NPCs (a bloody fucking nightmare)
i want to die

So npcs, its kinda important for any game to have them really, without them the player will get lonely and just overall bored. A good npc can be many things. A Shopkeeper that sells you weapons and has a charming voice, a piece of shit warrior that mocks you the moment you get to firelink shrine but guides you throughout the game, a rebel who is a spy working in a oppressive regime and saves you from going to Nova Prospekt who by the way still owes you a beer. In anycase these examples are some of my most memorable NPCs and it dosent take much to convince someone that the inhabitants of a world are equally important as the world itself.

Taken from the half life wiki

Going with the Half Life 2 theme, here are some of the best implementations of NPCs i have seen in any game. For context, Valve when making Half Life 2 has a philosophy, where everything happens as the player is playing. No cut scenes essentially. This made a very unique environment where the player can move and look around as major events are happening. As the NPC is doing something you can walk around, shoot zombies or i dunno, Shoot them.

Essentially the main storytelling becomes the environment. I remember my first playthrough of Half life. Right after escaping the train station i got to see the dystopian city of City 17. The NPCs walk around of their own. Screens with Dr Breen's face are everywhere, when i interact with a civilian they speak back, when i got close to a combine soldier they push me away. Do it enough times, they chase you down and beat the living shit out of you. While everything is happening i can still move around and look at the big fuckoff tower at the distance and i can appreciate the environment.

so thats the goal. Make a modular system that can facilitate this kind of world building. Sure i can just shove a big text or animate a beautiful cutscene which is argueably easier but where is the environment is that? By that point its a movie not a game. Not to say cut scenes are bad but it only works when the designer calls for it, Metal Gear Solid 4 is a famous example. With over 40% of the game being cut scenes, or 7 hours and 31 minutes (thanks IGN), but its still considered a good game because, THE Kojima Sensei developed it to be a stealth action cinematic experience, so naturally it will flow well in the game.

But for my game I will have to thank Lord Gaben for this enlightening knowledge.


The NPC System

finally, right?

Alright now the actual meat of this Blog.

The system consists of individual nodes that act as pointer for the NPC to know what to do.

Here is a example, actions run from top to down and its all thanks to the "action_cluster" node. Each action has a internal variable named "finished". its to help the "action_cluster" to track if the action is done or not. At the end of the action list it will do a "action_reset" meaning it will set all the finished variables to false and the loop starts all over again.

The "Scripted_ai" node is using a standard pathfinding setup of navigator_3d and navigation_region_3d. By combining this and and the pointers it creates a system where i can place paths and interaction markers to script a npc's actions. To be honest I never played around with the source engine's code so i am not sure how it works in half life but this is my interpretation of it.

the first test

Here is a simple interaction loop. Where it follows along a path, stops to interact, then follows another path to loop back to the first one.

there is a happy accident where by using pathfinding it can automatically find its way around obstacles that are blocking the way.

now mid development i needed to add a test model. Only to realise that the model dosen't rotate to the path. That's fixed by adding a simple script that find the difference of rotation against its movement direction. Along with that I made a simple walk animation and test interaction animation.

Along with those some changes are made to the interaction script. Mainly with adding a option to toggle between time based and animation based interaction. So the interaction marker now can be also used as a wait marker.

Overall this is a remarkably simple yet reliable system and can be used in a variety of different ways. I am writing this as i have just done this mechanic so i have no examples to give but i am sure you can figure it out yourself.


Future plans

and notes

Dialogue is a important part of a NPC. It can be done in many ways, many indie games love using text based dialogue as it dosent require any voice actors. But ideally I want to stick to voiced dialogue as it provides alot more atmosphere and energy than dialogue. Ofcourse I will have to program subtitles to accompany the voicelines which shouldnt be too hard.

Other important ones include a way for certain npcs to switch from scripted to combat mode. But the combat version is not done yet.


Thats it for now, not a big update but it is a baseline. Next up is the combat system introduction and rework, so look forward to that.

cheers

-Mellow