Hammer Girl Week 2
Creating NPCs and adding a Quest Giver.
As usual, we need to create another actor blueprint for our NPC and add a skeletal mesh (because this is a character with animation we don't use the static mesh option) with a custom collision box that overlaps all except the player pawn.
Moving onto the variables section we need to create a variable for each piece of information we want the NPC to take notice of. For a helpful tip, we can change 1 variable to an array of information without having to create an enumeration blueprint, to make a single variable an array right click on the little pill-shaped icon and left-click on the 3x3 grid of squares. This allows us to create multiple lines of dialogue for our NPCs without having to create 1 text variable for every line of dialogue or an enumeration blueprint for all the lines of dialogue, this way everything is stored inside the single NPC blueprint file.
Now is the time to make the NPC talk and program their animations. To start off in the event graph create the event begin play node and connect it to a play animation node then make sure to select the correct idle animation file in the animation nodes drop-down menu.
Setting the Text to say and duration. Here I use the blueprint event graph and variable I made earlier to decide what text the NPC will say to the player and how long they will say it for. Start by adding an overlap event from the collision box and then casting to the player blueprint (Hammer Girl) and setting the player in range variable to true and ending with a branch node.
With the Branch node ready we can start programming the speech selection functions for our NPC. For the false Execute pin, you can simply call upon the custom event "stop talking" and that's that, however, the true execute pin is where this section of code gets a little long. First, call the custom event "Talk" then set the text of the "Text Render" component using the value contained in the "Speech" variable array. Adding the "Line Duration" variable to a get reference node (drag from speech pin "Get (ref)") will inform the engine how long each corresponding line of the speech array needs to be active. Next use the set hidden in-game node to change the hidden status of the text render component (this should be set to hidden by default then revealed when the player gets in range of the NPC) and add a delay node but use both line duration and line select variables as the value of the duration pin for the delay node.
After the delay node, we want to add two integer variables together and set that value as the condition for our next branch node. You can retrieve both the ++ and <= nodes by dragging of the get line duration pin and typing in those respective symbols.
At this stage set the 1st branch true pin to the custom event "Continue Talk" and create a 2nd branch node off the false pin of the 1st branch node, the condition of the 2nd branch should be the loop speech variable. moving forward with the 2nd branch node true pin we want to set the value of the line select variable and add the custom event "Continue Talk" again. Finally, we want to add the custom event "Stop Talk" to the False pin of the 2nd branch node then set the text render component to hidden in-game once more, this way the text will disappear from the screen when the player leaves the collision box.
Quest Giver Code.
A Quest Giver is a type of NPC that will give the player missions to compete and because there is so little difference we can duplicate the NPC work we did earlier and add a small new section of code. This new section of code will require different variables then the standard NPC blueprint so be sure to add those now.













Comments
Post a Comment