Basic Interactions

Why use interactions?

In short, game designers can use Interactions to build complex behaviors without the direct involvement of a programmer.

Within Murder, an Interaction is an action that takes place between one entity and another. In a driving game, an Interaction might take place when two cars collide with each other. In a fantasy game, an Interaction might take place when the hero swings his sword at a menacing orc.

Interactions can be added to an entity just like Components. They even use the same menu.

Component menu, showing the Debug Interaction

But when an Interaction is added, it’s represented in the Architect interface as InteractiveComponent, where NamedInteraction is the name of the interaction.

Component menu, showing the InteractiveComponent with a DebugInteraction class

Hands-On Quick Start

The quickest way to get started with interactions is to jump right in and build something.

Add Systems

  1. Follow the Hello, Murder! project walkthrough to build a project.

  2. Add a new Feature named Interactives with the following systems:

    • InteractOnCollisionSystem
    • InteractSystem
  3. In the Game Systems system, add the Interactives system after/beneath the Physics feature.

    When finished it will look like this:

    Game Systems, showing the new Interactives feature

Create a floor trigger

  1. In the Hello World room, add a new Entity with the name “Floor Trigger”

    a. Select the Hello World room from the World asset group.

    b. Click the button within the Room folder. (If you can’t see the Room group, you may need to scroll and/or move the Room inspector).

    The World tab of the World editor with the Add Entity button highlighted

    c. From the pop-up menu, select New Entity, then Empty.

    The World tab of the World editor with the Add Entity button highlighted

    d. The new asset will show up in the list with an empty title. Click that title.

    The World tab of the World Editor, showing an empty entry

    e. An Entity inspector will show up below it – though it may look odd, as the title is blank. Select the Rename icon and rename the entity to Floor Trigger.

    The dialog for renaming an entity

  2. Add a new Sprite Component to the Floor Trigger entity. Set the sprite/animation as desired.

    Sprite component settings

    Here’s an 11x11 circle if you need one:


    floortrigger.aseprite
  3. Set the Position Component as desired

    Position component settings

  4. Add a Collider Component

    • Layer: Check “Trigger”
    • Shape: Select Circle or Square, size and position as desired.

    Collider component settings

  5. Add an Interact On Collision Component

    • Player Only: Checked

    Interact On Collision component settings

  6. Add a Debug Interaction

    • Log: Click the Set button (), then type “Stepped on floor trigger”

    Debug Interaction component settings

  7. Once complete, click Save Asset.

Make the Player an Interactor

  1. Select the Player prefab, and add an Interactor Component.

    The Interactor component on the player Prefab.

  2. Once complete, click Save Asset.

Test in gameplay

  1. Press F5 to begin gameplay.

  2. Press F1 to open up the Console window.

  3. Now move your character around. (If the character does not move, ensure your mouse cursor is not hovering over top of the Console window).

    Once your character steps onto the floor trigger, the console should show: “Stepped on floor trigger”

    Debug message logged

Built-in Interactions

Obviously, there’s more to a game than logging debugging messages to the console. But that’s the best part of the Interactions system – a game designer can build these systems without involving a programmer.

So, aside from Debug messages, what can Murder do out of the box?

  • Add Child On Interaction adds a child entity to the interacted entity.
  • Add Component On Interaction adds a component to an entity.
  • Add Entity On Interaction adds an entity.
  • Deactivate Child Interaction disables/deactivates a child of the interacted entity.
  • Enable Children Interaction enables/activates children on an entity.
  • Interact Child On Interaction interacts with children on an entity.
  • Remove Entity On Interaction removes an entity.
  • Send Message Interaction sends a message to the interacted entity, its parent, the interactor, or an the target of an entity’s Id Target.
  • Send To Other Interaction sends a message to another entity.
  • Send To Parent Interaction sends a message to the interacted entity’s parent

Believe it or not – there’s a lot to do here! And what’s more, these same interactions can be built to operate on interactions other than simple collisions:

Built-in Triggering Conditions

Murder also gives us a few ways to trigger interactions:

  • The Interact On Collision component and system, which we already used, activates an interaction when two objects collide.
  • The Interact On Rule Match component and system activate an interaction once a certain condition is met
  • The Interact On Rule Match Collection component and system activate an interaction once several conditions are met.
  • The Interact On Start component and system activate an interaction once an entity is added to the world.

What’s next?

Interactions provide game designers with a number of options to create interactivity without involving a programmer. What’s more, if programmers utilize the Interactions pattern in their construction, game designers will be able to leverage the existing structure to create even more possibilities.