03 First Interaction

In this tutorial we’ll add the first interaction to the game.

We’ll have a little chat with a random NPC in our town – to make this happen, we’ll need to set up multiple things:

  • interaction controller
  • interaction HUD
  • schematic
  • interaction machine

Interaction Controller #

The Interaction Controller is used to interact with any interaction within it’s trigger when the player uses the Interact key.

We’ll create a prefab that’s automatically added to the player.

Prefab Setup #

Use the Makinom Scene Wizard to create a ready-to-use setup: Create Game Object > Interaction Controller 3D

Change the following settings in the inspector

Interaction Controller Component #

  • Interact With Nearest
    Enable this setting.

Box Collider Component #

  • Size
    Set to X=1.5, Y=3, Z=1.

Create Prefab #

Create a prefab out of the Interaction Controller (3D) game object.

Remove the game object from the scene.

Interaction Settings #

Navigate to Base/Control > Game Controls and change the following settings.

Interaction Settings #

  • Interaction Control
    Select Interaction Controller.
  • Interact Key
    Select Accept.

The Interaction Controller settings handle adding our prefab to the player.

  • Add Automatically
    Enable this setting.
  • IC Prefab
    Select the Interaction Controller prefab you created.
  • Local Space
    Enable this setting.
  • Offset
    Set to X=0, Y=1.5, Z=1.
    This’ll place the interaction controller at a position matching our player combatant prefabs.

That’s it for the interaction controller.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

Interaction HUD #

Next, we’ll set up our first HUD – it’ll be displayed whenever an interaction is available.

UI Layer #

First, we’ll set up a UI layer to display our HUDs on. You can learn more about UI layers in this Makinom documentation.

Navigate to UI > UI Layers and add a new layer.

  • Name
    Set to HUDs.

Move the HUD between Layer 1 and Screen Fader in the data list, either by dragging or using the Move Up button in the Search, Filter & Sort foldout below the add/copy/remove buttons.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

HUD Setup #

Follow the interaction HUD tutorial for Unity UI to set up a HUD prefab and HUD.

Use the HUDs UI layer you just created for the interaction HUD. I’m also using the move from above and move to above schematics from the UI animations schematics to animate this HUD.

Dialogue UI Box #

Yeah … another UI box, let’s set one up for our dialogue.

UI Box Prefab #

First, the prefab – you can either copy an existing prefab (e.g. from the UI box tutorial or the UI assets)or create a new one. It should scroll vertically.

If you create a new one, use the scene hierarchy context menu: Makinom > UI Box > UI Box Scroll Vertical with Title

I’ll copy the UI Box Beige prefab from the UI assets – you can duplicate a prefab by pressing CTR + D while having it selected.

Adjust the UI box to be placed at the bottom center of the screen, e.g.:

Create your prefab, e.g. name it UI Box Beige Bottom Dialogue.

UI Box Setup #

Navigate to UI > UI Boxes and add a new UI box.

Base Settings #

  • Name
    Set to Beige Bottom Dialogue.
  • UI Layer
    Select Layer 1.

Unity UI #

  • UI Box Prefab
    Select UI Box Beige Bottom Dialogue.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

Dialogue Schematic #

Next, we’ll set up a schematic for our dialogue. Navigate to Schematics.

Settings #

  • Block Player Control
    Enable this setting.
    We don’t want our player to run around while talking to the NPC.

Actors #

Dialogue speakers require actors, so let’s set them up.

Click on Add Actor.

  • Actor Type
    Select ORK Player.
    This’ll use the player’s combatant.

Click on Add Actor to add another actor.

  • Actor Type
    Select Machine Object.
    The Interaction Machine we’ll use to start the dialogue will be placed on the NPC, so the machine object will be the NPC’s game object.
  • Set Name
    Enable this setting.
    We’ll define a name here – alternatively, you can also set up a scene object and add it to the NPC’s game object.
  • DefaultContent
    Set to Random Citizen.

Show Dialogue #

Add Node > UI > Dialogue > Show Dialogue

This node is used to display dialogues, choice dialogues, etc.

  • Dialogue Type
    Select Message.
  • Wait
    Enable this setting.
    The schematic continues after the dialogue.
  • UI Box
    Select Beige Bottom Dialogue.

The Speaker Settings handle if a speaker is used, e.g. to display a name in the UI box’s title content.

  • Use Speaker
    Enable this setting.
  • Actor
    Select ORK Player.
  • Show Name
    Enable this setting.
    The actor’s name (i.e. here, the player’s name) will be used in the title content of the UI box.
  • Text (Message Content)
    Set to: Hello there.

Rotate To #

Add Node > Movement > Rotation > Rotate To

This node rotates a game object to face another game object, we’ll rotate the NPC to the player.

We can also do this automatically via the Interaction Machine component, but let’s do a bit of animation here, for dramatic effect.

  • Object (Rotating Object)
    Select Machine Object.
  • Rotate Component
    Select Auto.
  • Lock Rotation
    Enable X and Z.
    The rotation is limited to the Y-axis.
  • Rotation Target
    Select Game Object.
  • Object
    Select Starting Object (you can also select the ORK Player actor).

We’ll rotate over time.

  • Fade Rotation
    Enable this setting.
  • Time
    Select Value > Value.
    Set the value to 0.5.
  • Wait
    Enable this setting.
  • Interpolation
    Select Quadratic > Quadratic In.

Show Dialogue #

Add Node > UI > Dialogue > Show Dialogue

Copy the previous Show Dialogue node and connect it to the Rotate To node’s Next slot.

  • Actor
    Select Random Citizen.
  • Text (Message Content)
    Set to: Oh, hi!
    Lovely day, isn’t it?

And that’s it for the schematic – save it, e.g. as RandomCitizenDialogue.

Adding the NPC #

Now, we finally add the NPC to the town. Open the World scene (Assets/Scenes/) and add one of the NPC prefabs to the town area.

You can find the NPC prefabs in Assets/Tutorial Assets/Prefabs/NPCs/ – I’m using the Casual_Bald prefab and place it somewhere near the statue in the center of the town.

Interaction Machine #

Add an Interaction Machine component to the NPC’s game object, either using the component menu or the Makinom scene wizard.

Learn more about interaction machines in this Makinom documentation.

Start Settings #

  • Interact
    Enable this setting.
  • Mouse Up As Button
    Enable this setting in case you also want to start the interaction by clicking on the NPC.

Machine Execution Settings #

  • Schematic Asset
    Select the RandomCitizenDialogue schematic you created.

The rest of the settings should be correct in their default setup:

  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Expand the Object Turn Settings, we’ll let the player face the NPC.

  • Turn Starting Object
    Enable this setting.

And that’s it – save the scene.

Testing #

Hit play, go to the NPC and interact with it (Space key).

The NPC talks to us, yay!

Next, we’ll add music to our game.