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.
But when an Interaction is added, it’s represented in the Architect interface as InteractiveComponent
Hands-On Quick Start
The quickest way to get started with interactions is to jump right in and build something.
Add Systems
-
Follow the Hello, Murder! project walkthrough to build a project.
-
Add a new Feature named Interactives with the following systems:
- InteractOnCollisionSystem
- InteractSystem
-
In the Game Systems system, add the Interactives system after/beneath the Physics feature.
When finished it will look like this:
Create a floor trigger
-
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).
c. From the pop-up menu, select New Entity, then Empty.
d. The new asset will show up in the list with an empty title. Click that title.
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.
-
Add a new Sprite Component to the Floor Trigger entity. Set the sprite/animation as desired.
Here’s an 11x11 circle if you need one:
floortrigger.aseprite -
Set the Position Component as desired
-
Add a Collider Component
- Layer: Check “Trigger”
- Shape: Select Circle or Square, size and position as desired.
-
Add an Interact On Collision Component
- Player Only: Checked
-
Add a Debug Interaction
- Log: Click the Set button (), then type “Stepped on floor trigger”
-
Once complete, click Save Asset.
Make the Player an Interactor
-
Select the Player prefab, and add an Interactor Component.
-
Once complete, click Save Asset.
Test in gameplay
-
Press F5 to begin gameplay.
-
Press F1 to open up the Console window.
-
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”
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.