Dialog and NPC interactions in Godot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Really nice short and sweet, thank you .. and especially helpful!

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/golddotasksquestions πŸ“…οΈŽ︎ May 03 2021 πŸ—«︎ replies

What would be the best practice for ensuring your character is facing the NPC?

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/solrbear πŸ“…οΈŽ︎ May 03 2021 πŸ—«︎ replies

Awesome! Thank you Emilio for Dialogic and the well made tutorials!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/Indieology_ πŸ“…οΈŽ︎ May 03 2021 πŸ—«︎ replies
Captions
today we're creating a simple example where you can go to an npc and make it talk so we start with an empty project we go to the asset leave we search for dialogic we select it and download it after it's downloaded we install it and we untick all the directories except the add-ons one which is the one that we want after installing you go to project project settings plugins and you select on enable for dialogic it has some errors i hope i can fix it in 1.2 but what you have to do after installing datalogic is reopening the project again so go to breaklist and you open it again now we have dialogic installed we can create a scene we're gonna add the player uh channel which is gonna be a kinematic body 2d let's rename it to player we're gonna need a sprite so we add a sprite what other sprite than the icon i don't know so the icon will be fine let's add some collision shape and the collision shape will be a square or rectangle and let's make it the size of our player so we have the player here click here to prevent you to selecting the child notes move it to the center of the screen and add some code to it let's attach script let's call it player and here on the documentation we're gonna go ahead and copy and paste this basic controller but we're gonna replace here where it says right left down and up since there are not actions that come with code i'm gonna add the ui and this will make them be valid because we have them here in project break settings input map we have ui accept which is the one that we're gonna use to talk and here you are left right up and down okay so that's all for our character we can save scene and let's call it main let's try it out select main scene and we can move our character it is a bit slow so i'm gonna up the speed to 600 here and yeah okay easier for testing now let's add our npc so to add an npc i'm gonna add a child node and it's gonna be an area to the node this area 2d node is going to be called npc the area needs to have also a sprite so we know who it is this case i'm going to do the icon again but i'm gonna modulate here it's gonna be red so we know it's not the player we will also need an area which we can add with a collision shape and the collision shape is gonna be a circle where you need to be to start attacking to the npc so this is the range basically let's also add an indicator because this area is not going to be visible in game so i'm going to add another sprite and i have this prepared here the question mark so let's add it here and move it on top of our npc and that is gonna show up whenever you are able to speak with this npc let's block as we did before move it somewhere here and let's add some code to the npc npc.gd since it's an area 2d first thing we want to do is body enter and body exit which triggers whenever a body goes inside of this area this circle area so it doesn't matter for one but we want to know when it goes in and when it goes out and we're gonna need two functions body enter body exited and we have a variable to check if the conversation should happen so if the npc is active or not two functions will check that the body which goes into the area if the name of the node in this case the name is gonna be player so if it hits player we set it to active and if it is not player we don't set it to active we said to false and now let's rename the question mark to question mark to differentiate it from the sprite and let's add in process that the visibility of this so if this question mark is visible or not is equal to being active so that means that whenever the body enters it's going to be active whenever the body exits is going to be inactive let's see it go in it's visible and go out it's not this will be our indicator that we can speak with the npc now let's create a conversation so we go to dialogic we create a new character which is going to be called npc we select the red which is the color of it and let's create a new timeline a text set by the npc saying hello i'm t and pc and smiley face if you want to learn how to use dialogic i made a tutorial so you can watch that video by clicking on the card or on the description let's rename this timeline to timeline 1 and let's go back to our code the code for making the interaction with the player is here and i'm gonna go line by line so first we're checking for input so this happens whenever you press any key check if there is a dialog or not because we don't want to show a dialog on top of another one so if there are no dialogues so in this case if dialog node doesn't exist so it's equal to null we start checking is action press ui accept so this is the key that you're gonna use to open the dialog in this case it's already defined here on project project settings input map ui accept so enter and space will work and we want to check that this node is active if you're not close to the player you cannot activate it but if you are you will we pause the game we don't want the player to keep moving while we are showing a dialog then we create it with dialogic dot start and the name of the timeline that we created in this case timeline 1. we set the pause mode to mode process because we don't want the dialogue to be frozen if you want to see another tutorial about posting a game you can click on the card or click on the link in the description then we need to connect the timeline end to an onpost function and finally we add the dialog let's create this and post function which is super simple we get the tree and pause we set it to false so that's all the code we need so let's try it out we're moving we see we press space and we see the dialog whenever the dialogue is open i cannot walk i press space again and i can keep moving so this is how you can add a basic dialogue to your game
Info
Channel: Emilio
Views: 7,306
Rating: undefined out of 5
Keywords: npc, interact, dialogic, godot, tutorial, movement, pause, npcs, talk
Id: gZ3h09B7Utc
Channel Id: undefined
Length: 6min 34sec (394 seconds)
Published: Sun May 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.