Starting work on NPC interactionMarte asked me if I could start working a little bit on talking to NPC's by having little speech bubbles pop up above their heads at the right time and then have text pop up when you press the right button and so on. I got started on the former part of that, i.e. speech bubbles.
As with the terrain editor, I'm focusing a little more on visual editing for this system as well so that Marte will be able to mess around with it without having to delve into tiresome and abstract code stuff — that's
my job, after all. It's a little more important to have things easy to edit when there's more than one person on the project (
which also made Unity a good choice for this game as opposed to my custom C++ engine for Vatnsmyrkr where the only way to edit levels so far is by editing an XML file).
The NPC-dialogue prefabSo just like with the autoterrain, I created a prefab to use for NPC's that the player is supposed to be able to talk to. More settings will be added, but here's the basic set that appears in the inspector when the prefab is dragged and dropped onto an NPC game object (tho the default direction is
left and has been edited here):
The script with a couple of variables as well as a circle collider where all you're supposed to touch is the radius. Perhaps I could move that setting to the script as well, but eh. It's for Marte who's right here with me and not just for any stranger out there.
Coupled with this, stuff to reflect changes appears in the editor view:
What we see here is the circle collider in green showing its radius as well as the
field of view (FOV) angle setting of the script. The circle's radius simply determines the
area within which the NPC will become aware of the player and the FOV its actual line of sight (so that it can't see behind, above or below itself).
Also directly reflected in the editor is the direction setting. As seen above, it has currently been set to
right and so that's the direction that our dog is facing. This means all NPC's have to be facing left as a default and then this script is used to change that. The reason for this is the final setting of the script: whether the NPC should automatically
face the player. If set, whenever the kitty appears inside of the circular bounds of the NPC, if the NPC is not facing the kitty, it will turn to do so, changing its own direction flag, which is why this needs to be a setting.
Finally, a little
speech bubble has appeared above the dog in the editor. This is simply a child object of the NPC dialogue object and can be moved freely using the regular transformation tools in Unity in order to fit each individual NPC properly. Its angle is always automatically set to 0, so that it doesn't rotate just because the NPC does. When the NPC flips its direction, so does the bubble with it.
DemonstrationHere's a quick GIF to show it in action. The settings in this case are the same as in the above screenshot of the inspector, but the dog has also been set to automatically face the player.
As you can see, the kitty and the NPC both need to be facing each other for the speech bubble to appear (talking to an NPC with your back facing it is a bit silly...) and the bubble also disappears when the player jumps so that a conversation cannot be initiated in mid-air.
Coming upNext is the actual dialogue system which is probably going to be a reasonably classic sort of box with character portraits and scrolling text as well as options to pick from and different pathways depending on the options chosen.
I've actually made a simple system like that in Unity before, as one of my first proper experiments with the engine, which was a less than complete visual novel style
game I made for Ludum Dare. Unfortunately the download links are broken as I haven't been able to pay for my web hosting lately, but at least there are screenshots that you can look at:
Apparently the way options were selected was a bit unusual in that one, but it worked IMO. And from the experience I learned that Unity has a limit on nesting in the inspector, which we I probably can't use that to edit conversations if they are to be too deeply nested, but perhaps this isn't that sort of game. If it turns out to be, then I'll have to look into something else. I stumbled across
this article the other day on the subject, which had some interesting ideas.
Anyway, Marte made a concept drawing for the dialogues in PUSE a long time ago, so here you are:
The size ratio between avatars and text box is probably a bit off, but other than that I think it's interesting to see both portraits at once. The background is going to be whatever is in the game at the time, a bit faded out (to white in this case, but perhaps black and other colours will suit certain other areas better) with the in-game characters disappearing and the portraits popping up.