Making NPCs with ChatGPT in Unity!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the second video about using openai API to make games in unity in this video I will show you how to use Ready Player me avatars Unity starter assets and openai API to make smart NPCs let's start so first thing I'll do is go into Unity hub and creating a new project well your Hub get stuck sometimes like that they still didn't fix this issue but yeah let's create a new project I'll pick 2021 for this and I want to be urp because uh this is going to use urp and the new input system so I want it to be working pretty much without any problem and let's call this project um red player me smart and PC so this should suffice and let's start it the idea is to use Reddit player me avatars open AI package and open AI API stop Unity uh third person starter assets project from asset store and these three will come together to make a very basic system for us we will script ourselves a dialog system that triggers with an event and so we will start chatting with napc in the game world that can talk to us in certain subjects that we provide that we've wired that MPC to talk and yeah so this should be pretty much that so what I want to do is the lead foundations and work the basics of it right after that we can also discuss in some other videos how to make these and pieces more distinguished more unique in a way that they really feel like a part of the game world and they you know you feel like there's infinite possibilities you can't talk with them so there is so much we can't discover I'm also quite uh excited I find out some of the things as I work on this kind of side projects and I really want to share all of these with you it's still loading probably I will cut this kind of Parts where it keeps loading so bear with me yes that did take a while let's make it full screen and here is our Unity I'll just get rid of this error messages they don't mean anything and here we have our fresh project first things first I want to go to a GitHub by the way I will drop all these URLs in um the YouTube description please take a look at them and follow them first thing is the open AI Unity package that I created you can find in my GitHub account so first I'll copy this git URL here you can see it's ending with Git I will copy this I'll go back to Unity window package manager let's move it here we click on the big plus icon add package from git URL the paste URL here click add and it should be coming so the thing is uh I previously worked with that package so I have all the setup here if this is your first time please watch the first video about this ongoing series have your setup ready also in the readme file of this project you can see how you can do the setup the important part is here having a open AI account and saving your credentials in your local so you can actually make requests to open AI when the package is selected in package manager you can see the samples and I will import the chat GPT example because I will actually copy paste some stuff here and use directly so I do not need to write the code from scratch I'll just move this window here and let's open up this chat GPT sample scene that we imported from the package let's run it and well see that it works and I will just say hi and expect something in return which comes back hi there how is going on all right so the package is working the second thing will be [Music] um getting the starter assets you can go to asset Store and search for starter assets third person and this is a package directly from Unity that you can use for creating you know like starting off with a third person example it's pretty cool other thing is it is not available as a package but you need to go to access store and edit your assets so you click on this button add to my assets I I already have it um however it should ask you to uh it should show up a button that sends okay yeah this says opening Unity it shows this pop-up you click on open in unit editor and it's gonna send us to Unity package manager where we can see my assets so you can also click here that if you haven't if you have purchased anything from Unity uh App Store uh you need to access store you should see them here as well for me it's bottom here you can click load to see if you have like quite many packages there starter assets third person character controller zero here I'll just click on import and get it so it has dependencies of itself so we should also install them and let's just wait for it going back to it it's the starter assets third person character controller so it has this map animations and the character itself is going to make things uh quite fast for us so we do not need to deal with wiring all these things by ourselves so starter assets use uses the new input system we will have to use it so I'll just uh click on yes here and well okay it was too late we haven't imported yet our unit is going to restart then we will need to go and import the package content so the UI dialog prompt kind of blocked the import process we couldn't import it but we switched to the new input system this is necessary for this example to work so um again Unity started we have package manager here on my assets tab I'll click on load here I'll go down yes starter access third person character controller I'll say import this time it's not going to ask about the input system change but shows me the package itself right away I import this and we should have a system we should have a folder called starter assets and we can go to the sample scene in there the idea is to get a readable Avatar and replace it with the robot character we have here so we can make personalized avatars and use them in unity directly in this example so it is here so we now have the starter assets folder in it we have [Music] third person controller folder scenes and playground so this is uh where I would like you to go and we will have this example seen here and here is our character with us animation camera rig and everything I can click play and already see this guy in action so we can walk around I can jump I can run and also I have falling animation so everything is here so this just works let's close this like I said the idea is to replace this with a red player Avatar and we can have our NPCs as red player me avatars too for that we will need Ready Player me SDK Unity SDK so one thing you can the current way to get ready to play me SDK is that you can go to documentation docs.creativeplayer.me and go to Unity tab there you will see download and you can go to a Google Docs and download the latest package which is released uh less than a month ago and the thing is we have been working on changing certain things with the SDK actually now we made it completely open source and you can see different components in it and you can contribute to it so you can go to github.com Ready Player me slash Unity Dash core this is the core package that loads other mandatory packages and likewise you can just go to the code button copy this and import it this is still in Alpha phase and we haven't notified many people about that if you casually go to Red Ready Player me GitHub organization definitely you will find this out and we just sent uh information to our early Partners who wants to test it out you might as well test it out see it for yourself and that way you can let us know if there are any bugs or anything you want us to improve or fix that would be incredible we also have the discussions here so issues discussions all of them are welcome feel free to help us out with that let's go back to Unity and get the package I'm going to package manager plus button add from git URL let's paste it it's ready to play Unity core and add like I said this is Alpha phase things might break you might see lots of error messages so be aware basic functionality everything works so far we will be acting on all the issues we see as soon as possible so if you let us know it would be incredibly useful right now we use a gltfs instead of gltf utility to load avatars which is faster much better we can use compression and everything and there will be even more features coming along with that okay it asks about uh burst so we will need to flush the editor and gltfs will prepare itself and all should be fine so uh once it's done you will see every player me uh fold out here and there will be ready to play me Avatar loader core and webview what we are going to use uh technically by loading avatars right now in this case is core and Avatar loader webview is for mobile uh display of the website inside the game engine I will see some burst compiler burst package related bugs this show up sometimes it's coming from unity's burst package so you can totally ignore them at this moment we will also take a look at how to get rid of them in the SDK itself once you do it you will see this Ready Player me uh menu here and this is where we load avatars if you already know what Ready Player me is this should be quite familiar to you and so first of all uh let me show you the Avatar loader window and the settings window first thing I want to do actually is that um I want to pick Avatar config because right now it's going to use a demo sub domains default settings instead I'm gonna use the high quality avatars so when you click on this area you'll see this empty list click on this eye icon here so you can see the settings coming from the package itself I'll pick High and close this window so all the Avatar's eye load are going to come with the high texture and mesh quality and this is coming from editor config that and Avatar I loaded before instead I will go to read the player me website and it will direct me to HUB since I have an account I want to go to my avatars um let's say I'll pick this one and copy the glb URL so you can make avatars edit them and once you make them you will let into this Hub and you can actually get the URL of the avatars and paste them right here and load it into the current scene so this is this guy is going to be my main Avatar I want to do it the way that um it starts with you know uh avatars already loaded into the scene rather than loading them in runtime at least for this time I will just uh name this Avatar in the scene and there I have it I would like to have a second avatar which is going to be the MPC this was the girl uh you already saw in the main scene so this is who I want to have the person that I'm talking to uh there will be there will also you you will see this button here you can also download the glb file right away or copy it up with our link since we want to load it through the SDK uh copied URL go back to Unity paste URL here and load Avatar Into the current scene and there I have my second avatar so first of all um let's call this NPC I would like to create like um empty game object here let's call it the NPC uh setup let's move it to transform zero and drag the MPC inside what I want NPC setup to be is that um that it holds everything about this MPC uh dialog scene or setup that we will have so um what we could do is um for example let's um yeah let's make our Avatar sit here the our MPC uh sit here and when we we can have like a trigger box collider around here and when our Avatar gets in the collider uh we fix the camera somewhere and position it in a way that they are having a dialogue and then we boot up the chat GPT uh UI so I'll take uh her here I'll position her a little later but she can already stay here so before we brought her some animations before then um what we need to do is setting up our Avatar so you remember when I was running the scene I can see my you know robot walking around running jumping I can just pretty much do everything with basic controls um I want to have all these abilities on my avatar itself what you can't usually what you would do is actually uh go to this player player Armature um it has all these components animator character controller third person controller rigid body push inputs player inputs and whatnot also in the player camera funnel uh it has this animation virtual camera and the follow is set to this um camera player root that very camera follows in this object so what I would do is I go one by one create all these components on my avatar set their values from here and then create this uh player camera root object in here set this into the camera and then go of course this is one way to do it another one another way to do it is by script that I already made a video for this before you can find in my YouTube I'll try to drop a link right just now and the idea was that you can do all of that by a script just selecting your avatar and you know generating those on top of your character um I had a public GitHub repository for that called red player me and unity starter assets and here again I will paste URLs for these in assets folder editor I have this third person controller Builder uh third person character builder script what I'll do is I'll just copy everything here come back to Unity create a editor folder the editor scripts should be in a folder called editor regardless of its location in assets folder I'll create the c-sharp script third person character Builder and let's wait for Rider to start and what I'll do is I'll paste what I copied from GitHub right in here so uh file names are same character builder all right so this is what I have here please watch the video I step by step explain what I did here then all these parts and steps that that are also commented will make sense to you the idea is that just buy one click I can transfer all this information onto my avatar as well and I wouldn't need to do it manually especially if you are creating lots of avatars this is going to be replaced in the scene and you will need to do that again and again and again rather than going through all the character all the components and duplicate them we can do this quickly so how this works is I'll select my avatar go to redplayer me menu and there is this button option setup character I click on that and voila I have animator setup with third person start process animation controller character controllers here inputs are here pretty much everything set for this one thing fails to set sometimes is the player follow camera so select player follow camera and you will see that it's targeting here both of them this this looks all right I'll just um uncheck uh disable the robot character we had so we don't see it I'll save the scene like that so I have all the system on it and let's run it and see if our character is moving as expected it does but the camera doesn't follow most probably camera follow had an issue and again I do not know why this happens but it's looking at the uh disabled characters camera I'll just drag and drop this in here manually save it again and it should work yes now my avatar is fully animated walking around jumping pretty much does whatever uh the default robot was able to do now the idea is to set up our MPC so we can have a conversation with her nice so what we did so far was um import open AI Unity package uh imported starter assets that brought us the character and controller camera rig and this basic map we imported Reddit player me SDK and uh then we brought this third person character builder script from another another Unity GitHub repo I had and set up our Avatar what we did was either we were going to create these by hand taking a look at the player Armature character that was in or use this so we went the fast lane and the second thing is uh probably I should take a look at that later and figure out why that happens but for now you can just set the follow in player follow camera to our avatars camera Target manually and save the scene so that also should do it now we have this working system here so the next phase is uh getting some animations on animation controller to our MPC because um we can start setting our environments for the dialogue event we are going to have and for that I will create a folder called animations I will create a animation controller called let's call it NPC animation controller and for animations I will go to mix ammo um what I can do I can get two sitting animations one is Idle sitting the other one is uh sitting and talking so when we get a reply from chat GPT we can actually play another animation that you know makes our avatar look a bit more alive I'll search sitting and yeah we have quite many animations here um so there is this sitting and talking let's take a look at this so it seems all right cross legs and characters talking looking at this direction or maybe we can mirror that because um so she's sitting here probably she would look this way rather than that way we can position our characters uh teleporters somewhere here so that would make sense uh so so she faces us that way I'll uh download this so what we want to do is get um fbx for Unity and with skin and download this when you download without skin for some reason fits get messed up in the animations from mixamo I do not know why but so that is the way it is and the other animation could be some kind of a idle animation uh sitting uh there is sitting idle so here she does nothing I hope the height of the setting is the same because this has legs crossed and this doesn't probably it's going to it's not going to look so smooth uh to be honest but well for this prototype case it just does work so we don't need to really bother uh ourselves about that and yeah I downloaded both of these animations so they are in my downloads folder I'll just drag and drop them here in the animations folder so I have them both what I'm going to do is Select them and change the rig to humanoid because they come as generic this should be humanoid apply let's check how the animation plays it's all right just an idol name is sitting idle and select this one rig humanoids apply this and this is how this animation looks it's called animation tab and this is here so um what is going to happen is uh we received the let's say uh we have a trigger for this we receive the reply this animation plays starts playing but this animation seems to be quite long around 50 seconds this is too long what I would like is to get some 10 to 5 Second animations just we can see the hand motion so it you know looks like something is going on so we can actually cut a part of this let's search um let's search a good section that we can get so no movements Head Starts does something gets back so we can cut this part like maybe from five to ten seconds um again you can do something different you can get a different section or you can set your animation you know like system differently for me it can okay let's see it starts from hands down and okay let's move it a little more in yeah so starts hands down and and sends them all right so I will apply this like that so we can have a shorter animation I'll go to animation controller for the MPC so uh we will start with idle animation then we will switch to sitting and talking animation and we can have it with a trigger so it's going to be one shot we'll wait for this animation to end then we'll go back to idle again and I'll go to parameters I'll create a trigger parameter and call it talk so when it receives the talk signal it will transfer to sitting talking and when it's over it will go back to make that I will click on setting idle and actually I will click on the Arrow from setting idle to sitting talking I will say no exit time so whenever signal is received it's gonna switch to sitting talking not gonna because sitting idle is also um quite long uh animation I suppose it takes yeah around five six seconds and sitting talking is around six five seconds 4.5 seconds too so I don't want it to go to all the way when we get the reply animation starts when sitting talking ends it goes back to either Loop and yeah uh one thing that I forgot is we should Mark them loop as well um idle can be Loop but we do not really need to do the loop for talking regardless um we can make that just in case and that would be it so we have our animation controller animation controller animator controller for the MPC let's select our MPC and drag and drop our animation controller to it I will run the scene and see you know this is going to start with the setting idle animation I want to see what it exactly lands and I can position it correctly then um you know uh use that point to reposition it so when the game starts it is sitting at the right corner let's start this I'll go to scene uh tab okay well to be honest they make some animation looks quite horrible because yeah hands are going down the legs and all uh I really can't say I'm really happy about oh this looks uh but uh regardless I'll just so position it like this and I can bring my animator top right here come on two trigger my talk okay I need to select my NPC come on oh we haven't actually uh selected trigger for that just yet I suppose okay UNT UI just don't break right now so um well yeah we need to set the condition so we only have one parameter and it is talk and what we said that there's nothing else when we receive the talk signal it is going to go to sitting talking and once this finishes it goes back to setting idle so we didn't have this condition here I'll go back to the game let's run it going back to scene View and let me move it maybe here boom when it's over it goes back well it does look ugly um maybe there was like um sitting talking okay there's like another sitting but this has the legs crossed in the wrong way oh but so since we already mirrored this one our legs actually should look like this um yeah actually then I will download this one so let's just get it sorry for this inconvenience and this is called just sitting I'll go back to Unity uh sitting idle I'll just get rid of the sitting idle animation I bring back bring this new uh setting animation so okay this should be all right um it just sits like this again going to rig tab making it humanoid and applying it um I should also make this animation Loop and applied it again I got animation controller because now we lost the sitting idle motion and I'll get this sitting animation too right here in the motion field let's save this let's start it going to scene and let's give that that signal okay so there's not much of a shift which is good I'll just uh pick her um and position it in a way that it looks like she's actually sitting in here maybe can rotate her a little like that too so she's leaning uh on the wall so let's move it yeah she doesn't really into the vault yeah and let's give it a talk signal okay so what I'm going to do is um copy the transform component copy the whole component because we have a rotation and location informational and then I will just paste the component values I run it again just to check that yeah it's transformed to the right place it seems so talk signal and this is a one thing I want to do is I want to rotate the um direct light so when we have this discussion with her actually we can get the light too her face so it looks yes uh we can see more details because otherwise it's all in the shadows um if I make it 190 degrees it should look all right stop it 190. and we will start from here saving the scene so we have our MPC animation controller set up as well the next thing I want to do is add my trigger I'm going to I'm going to add uh empty game objects here let's call it event trigger and it is going to have a box Collider so our event triggers right in the center of the map I'll bring it here in front of her let's go to top view so I can see exactly where it is um I'm gonna make it Maybe three units in x-axis and three units on y-axis so we can put it right here like that so yeah if you are walking through here through the to the stairs you don't get affected but when you get into this area you will get caught in the dialogue with her right and let's move it up actually I can make it like maybe three units up as well because I don't want you to yeah there's a chance that you might you know jump from here probably in this and you will still get caught in the uh dialogue well doesn't matter the the area will be this area that you see and let's mark it is trigger so it doesn't block us physically but just lets a script know that we entered that area and um I would need a point to transfer my avatar to so it's like dialogue started I need to you know Caleb I need to be teleported at a point that makes sense in that camera angle so let's call this standing point I will give this um icon so I can clearly see where this is move it here and let's make it a round icon right so um yeah I'd imagine so she's looking this direction and we would be here too if we got the rotation and location of the yeah object so we would look at her as well uh blue Zed is forward axis so this is where we would be looking sorry and yeah so this should pretty much be it and I don't know maybe it's too close we can figure that out later and the thing is we will need a camera I do not want to transfer the cinemachine camera here what I want to do is have a secondary camera and disable main camera then enable the secondary camera and when you are out if you do pretty much vice versa so there would be some kind of a camera switch there in that frame when we enter so um in the MPC setup I will create a camera we can already see the uh how how that sees the environment here it's at zero point I will bring it here I'll go to top view again and let's rotate it 180. so probably I would have it on this corner looking here so it would capture a H so let's make it like like this pull it closer maybe move it up a little and give it some angle like that and like this so cameras looking down uh on the characters she's sitting here our character would be on this point and well as yeah as we see how the this this angle looks then we can change the position of the camera later but yeah this is this is all right for now so uh how it's going to look is that um the NPC here our character here and we can place the the input field and the text field up here and down here so it would cap it would it would take the center area make that part of the screen busy and on the sides we would be still able to see our characters and yeah this looks like it so the next step will be we will write a script to get the uh capture the trigger that some object entered it and if it's the player then well we do the magic disable main camera transfer the Avatar to standing Point enable the secondary camera and later do the chat GPD stuff haven't got there yet but let's continue with the script I'm going to create a scripts folder we don't have it let's call this Scripts and in this um I can call this NPC dialog you can call yours whatever you like and I will attach this to event trigger game object because it has the box collider and I want to get the entry granter signal from this object in this script so this is well at least doing it this way it is important that the script is on this game object let's open it up and get ourselves on trigger enter so I have the on trigger enter method here first thing I'm going to do is check other compare tag and it should be clear let's make sure that our Avatar actually has player tag select Avatar and yep it does have player tag when this was set up is in the setup character phase so in that editor script we already did this and now so what we want to do it is the player that entered the Collider first of all uh disable main cam enable dialogue cam and then what we do is um teleport car two standing point and camera camera is there am I missing anything let me think so we disable the main camera enable the dialogue camera we look at the place then we teleport Avatar it is right there oh one thing we need to do is um uh while there our Avatar will be still able to you know capture inputs and everything uh one thing we can do is actually disable uh its player input so it doesn't get affected by the buttons anymore so that is important as well so we do not want it to you know like uh keep running or walking around while camera is fixed to the dialog so they Mouse and keys do not affect the character so this is what we want um disable player input and anything else or also um as a last thing we can just yeah just remind ourselves that uh we will show the GPT chat UI here and of course um we will also have a you know recover kind of function because uh when the dealer goes over you know like uh what I was thinking we to start with this example we can have like a leave button to leave this dialog and then once we click on it we do the reverse of whatever we did here then it waits for you to enter the collider again to initiate the discussion and so uh to start with that we will need references to some of the things here so for example the main camera and the uh secondary camera we have let's create private fields for these um we won't get the cameras directly we will need the games game objects of them so we can disable enable them we won't do anything with the camera component itself object main camera and copy paste this and capital c and let's call it dialog camera so and then what we will do is main camera selective false and double camera set active true and we create our standing point where we want to teleport our Avatar let's take a look at it again so what I'm gonna do is uh I will also attach this to the inspector and when character enters the trigger boom it will be having its uh rotation and position so we can directly look at the MPC and stand there for the dialog for that posing for that camera angle pretty much so let's have it here as well serialized field attribute private transformed this time because I want to get the position and rotation of it rather than access accessing through a game object we can directly do this standing point and what I will do is uh the so other is going to be our Avatar so here actually I can just cache its transfer Avatar equals other transform and what I will do is Avatar position equals standing Point position and Avatar rotation equals standing point rotation and so we got the Avatar transform Avatar get component uh player input from input system yep and what I want to do is disable it enabled equals false I suppose this should be enough and then showing the UI that we will do shortly later um yes okay let's give this a try I wonder if everything is in order and I will run the scene oh okay one of course we haven't set any of these yet and I need to disable my camera from the start so uh it doesn't capture anything even trigger has standing point dialogue camera and the main camera all of those are now set secondary camera is disabled let's run the scene right now and all right boom so let's see how this look all right so um it did not transfer Avatar here and one of the reasons this happens is that um uh some kind of a frame interference uh I would say it teleports you here but uh kind of a character controller runs uh one frame later as well and teleport like pretty much teleports you back to where you were supposed to be with this uh control so uh on trigger enter in a way runs faster um kind of a trick we can do is delay it a little so what I'm going to do is I will make the own trigger enter a synchronous method and right after actually so I will move maybe I don't even need to do that I'll try this quickly um so I captured the transfer I cached the transfer from the other immediately I switched the cameras I disabled it player input then I teleport if this doesn't work I will just add like a small weight in between these making on trigger and asynchronous Method and see if that works so again um I'm capturing this right away so I can use it in those two places first I will disable the player input then I will teleport my character to the standing point this Orange area all right let's run there boom uh it seems like yep it still didn't transfer there it's where it's supposed to be as walking then let's pull this trick so bone trigger enter is now a asynchronous method this is something you can do with um event functions of mono behaviors actually if you didn't know um what I'm gonna do is I'll just wait a task delay of let's say as far as I remember um update lost about 20 milliseconds in unity but just to give it a little buffer I'll just say 50. um again in built applications difference you know like um computer specs this might be different to be sure you can increase it or you know uh do something else make sure making sure this runs next frame in a way uh so this is gonna wait a little and then run it you can also try making it uh like a core routine like enumerator and yield return null in between or yield weight for next frame to see as well but uh this should also work go back to Unity run this we might see a little freak flicker because of the camera boom yeah that happens I do not know if the video uploaded into YouTube viewer you would be able to see that but um I was able to see this one frame flicker so it was pretty quick but maybe moving the um like doing this uh right here would help with that like moving the cameras switch to a little later so camera renders after the position has changed um I'm going to run this well if if that doesn't get rid of the flicker not really not a big deal boom yep it just worked so this is going to be our main setup I think I can already take control of the um camera here and you know try to play around with that to you know make it look nicer wow is this more too much come on holy alright so uh we can have the dialogue system like in the center area right here and our characters are having this discussion actually field of view is 60. I would like to have it be 45 actually because 50s UH 60 is quite High looks like um fisheye in a way I don't like that let's move it to this way a little okay this looks all right um I'll just copy the component properties here for the camera and when the scene is not running I will paste it all right well let's give it a try again I will run here boom so I cannot use Mouse on camera here one thing I forgot was the cameras field overview to 45 so that's also set now nice The Next Step will be actually bringing up the GPT chat UI so do not need to do it from scratch we already imported the sample uh from GP to check chat example from the open AI package I'll just go there I opened up the GPD chat sample scene from this path right here I will copy the canvas and GPT object which has a script on it I do not need to get the event system or anything else because we already have them in the other scene I selected them I just Ctrl C copy them and come back to third person controller scenes playground and I will just paste them here what I want to do is also I will not disable and enable them depending on uh you know when we enter the trigger as well so camera is also X the same way what I'm gonna do is I'll create a empty game object let's call it it has camera and UI it's called to activate so probably you can find you know nicer names for uh these let's make it okay this is a zero you can find nicer names for this game objects just for the sake of this uh example I won't really not kind of worry much about that I enable my camera back again and I disabled it to activate a game object and in the event trigger I would also like to replace my dialog camera with to activate and it would also make sense to rename this uh uh game object because it's called to back actuate egg G ways uh no I do not need that and it is also renamed nice so we have it here let's take a look how the UI looks and you know we can make it nicer I'll just enable this to activate field so this is how it looks uh two large blocks our characters uh what I want to do is go into the canvas let's pick the image area um so the image is the actual text area let's call it because it has a text field in it this whole white thing and I'll pick this I will uh stretch it to the top like that and I will give um or I will make it um stretching in the center how I change this view is um I click alt so I first click on this uh thing here this icon here then I click alt button then you can see all these options then I do alt shift it also gives me the pivot point where you start from so it's alt shift stretch in the center boom so what what this helps me with is position it and give it a center as well so what I will actually do is this stretch top like that and I will actually or I can just do like this I can yeah the reason is that I want to give it a width of 600. I want to give it a height of let's say maybe 200 and position maybe -20 so it should be here well maybe 500 is much nicer because I want our characters to be visible and all right let's go to input field so the same but for button part I will do the same with input field and the send button so let's move it here let's give it a width of 500. so it does the same with that uh height is all right let's move it up 60. uh pixels and for the button we have alt shift this corner and so this is all right let's so yeah that that that's not gonna suffice in this case I'll take it to here then yeah I wanted to move with that you know Century um one thing I can do is instead of giving them 60. I can create a game object here yeah sorry you know I just figured these things out right now as I'm working on it with you so I'll create a game object and call it panel so I can actually give it the size in the center and you know put everything in it uh let me get to a view like that so what I want to do is like I want it to be you know something like that so everything fits right inside um I will make it like stretch uh again shift alt after clickings I'm gonna stretch it to the center and I will give it a 500 with then I will move everything inside and I will make everything have the full width so that would make things easier for me and selecting text button text area button input field all of them put it inside and then let's say yeah just take the whole top and minus 20. nice so I do not need to worry about their width anymore and I can stretch them as I like and again this was 60. I'll actually give it a padding from the side so I can have the send button this button can also go to the corner 60 and I can actually make it with like a 60 as well I can also duplicate it to have another button which is close button because um right now we only have one button and no way to close this dialog so we can have the button for that let's also rename this send so we can distinguish them and I'll make the input field have some bright padding let's say 100 400 Maybe 60. and send button would be here but directly here or here so call this padding 60. and make the input field 40. 20 yeah 120. um so text area stretches top minus 20 padding 200 height input field has stretches to bottom 60 wide position to write to 120 padding and sending close buttons also uh to this corner but has some padding and let's change the text over the close button to close and also we can give them a little color too hint that what kind of button they are so this could be tinting a bit too red and sand con sent could have a greenish color so that would you know mentally let us know what they are about if you click close this whole thing goes uh we called it this reverse thing that you know sets everything back to how they were and it looks all right I will disable to activate and let's go to the game all right so I will run here and okay we missed something again okay to activate was after changing the variable name we forgot to reset that uh saving it going back to the game and yeah so uh yeah the thing is I do not have any Mouse right now because in the third person controller it gets locked so what I need to do is actually um yeah in the MPC dialog script this part I can actually now call display cursor and what I'm going to do is cursor visible equals to and cursor lock State yeah lock State should be unblocked or non yes none because the state when it's locked is locked so this is what we have and that we should have the mouse cursor free that we can actually interact with the UI go here boom the NPCs here my avatar is here and I can tell her hi and yeah she replies back to me so the last thing now we are going to do is wiring the close button so we can get out of the situation and whenever we receive the reply from open AI I can actually play the animation for the NPC and we can finish this almost there let's finish it so um close button before wiring we need to anti-method so whatever we do here we need to reverse that and let's call this a public void method which is going to be a color you know reverting all these changes so um one thing we should do is actually I will cache this uh locally in this class because we will need to use this Avatar transform and yeah I will not have any trigger you know like uh parameter or something so I will not know where that is so I need to Cache this so what I can do is actually take all of this here I will not need the delay I will just remove the comments as well so I will set the player input through so I can get control I do not need that the Avatar can continue from from the point it was and cameras we are switching now then main camera will be enabled to activate area that has the UI in it will be disabled so this is false and cursor is going to be not visible and we will lock that for the purpose of moving it around so it can always stays in the center so we have the recover method here and what we are going to do is go to Canvas and find our close button uh in its button component we can add a on click event let's drag our event trigger right in here from MPC dialog component we find recover method all right so we click close uh it closes that's what is going to happen let's play it quick try and boom all right everything is fine I go out I come back in again close I come back that's so right that's it so and the last thing the animations where we are going to trigger the animation so we need to know when we actually receive uh responses from openai which is in this chat GPT script it doesn't have a way to notify us so we are going to actually modify that um so what happens is we make our call right here uh we receive a reply from that and pretty much this is here we kind of know that uh we received the reply from chatgpt so this is the point we can actually have like a um uh unit event to invoke and let anybody any component subscribe to it know that a response is received so what we are going to do is um I create a public Unity event let's call it on reply received so it doesn't only players it doesn't require a type at this point it can be anything we just want to notify if anything's right invoke so this is this is the time to receive a reply and in the UI we should be able to see this uh event area right now since it's public thing pylon nice so let's add an event here so what we are going to do is uh we will get our NPCs animator and find set trigger and the string for that trigger was let's go um it was talk so GPT component from the UI we brought we created this event inside the script I set NPC's animator and we will call every time it receives a reply from openai it is going to start the talk animation I play this let's go I'm here I'll say hi I should get yep the animation is plain yeah yeah it's not natural it looks horrible to be honest but this is mixed summer for you I'll blame mix Samo but still uh we can make things work I'll say what is this place the chat room where people all over the world can come together and chat so because um we still have the again if you watch the previous video uh we had this prompt here says act as a stranger in a chat room and reply to questions uh there is a reason so this is where we can actually you know like spice things up um I plan to make another video about how to make NPCs for games and there are quite many nice tricks I found which looks really cool really impressive I want to share those with you uh in a like a continuation video to this um let's say act as a so let's change this act as a Reddit player me Avatar pinned metaverse that lives in a unity game engine C and helps visitors uh find answers to their questions I will actually divide it into multiple lines this getting out of hand towards helps and questions helps visitors find answers to their questions using her um connection to open AI wow that that this sounds quite futuristic so we pretty much kind of set a very basic personality to this character it will know uh you know where it is what it isn't it's going to relate all the questions we ask to this context so and let's try one last time before finishing this video let's run it let's go up to her and boom hey who are you and she says hi there I am your red player miyavatar I'm here to help you okay not mine so we need to make certain things clear in the prompts definitely I'm here to help you find answers to your question using my connection to open AI feel free to ask any questions I'll do my best to help you out okay why this place looks so basic and blocky yeah I mean you know all these grids and everything yeah anyways I'll I'll keep it long that's here well my home is built on unity game engine so the graphics might appear a bit blocky I'm here to make sure you get the information you need just ask away what is this place what is this place this is a metaverse a virtual space where people cannot like us can interact virtually I'm your guide here so if you have any questions I'll do my best to help you out where is where is other people metaverse is lost and there are lots of people around you can find us you get the point so I pretty much have this kind of interaction system where you enter uh you have to enter your questions and send them and let's close it and get back to our mirrors I really want to try this I'll try to jump into the interaction point before we end this ah didn't work I'll do it again yeah seems like the teleport didn't work at all in this case because the fold was continuing so we figured out bugs on the way but anyways and yeah we could definitely clean the uh chat history and stuff like that or you can just um clean the UI it can keep the rest of the conversation to add on top of it uh this is pretty much it and I plan to make this uh you know NPC system more complex maybe have some components to build uh MPC brains in that way there are some other really cool tricks to make things uh work differently I also want to show those to you to me I'll cut some parts of the video to make it faster but it's already over one hour so it's already long enough um this uh all these URLs and this example will be available in the description of the YouTube video that GitHub GitHub URLs and everything and other than that if you found this useful uh subscribe and like the video you might as well share it with your friends who are really interested in game development using this new AI tools that are evolving and booming all around so thank you so much for making this far if you did or not thank you so much and have a nice rest of the week
Info
Channel: Sarge
Views: 27,884
Rating: undefined out of 5
Keywords: unity, unity game devlog, unity game dev, indie dev, game dev, gamedev, unity3d, devblog, game development, indie game, game ui design, indie game dev, readyplayerme, ready player me, unity starter assets, starter assets, third person controller, third person system, unity third person, gpt, gpt3, chatgpt, chat cpt, gpt chat, openai, open ai, open ai api, openai api, ai game, ai npc, avatars, metaverse, chatgpt in unity, chatgpt tricks
Id: Cg4k-XPBC2Q
Channel Id: undefined
Length: 77min 37sec (4657 seconds)
Published: Mon Jan 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.