Skip to content

Interactables and interactions

Chris Sprance edited this page Dec 23, 2024 · 1 revision

Flow

  • Enter component area
    • ComponentArea runs a CanInteractWithQuery when the entity enters the area
      • Pass = Interactor(CanInteractWith, Interactable) added to Interactor (AKA Entity that entered)
      • Fail - Nothing happens
    • InteractionSystem
      • Query: Interactor(CanInteractWith, *)
      • Process
        • Run through all interactors that can interact with stuff
        • If an input is pressed that matches the use key
          • Relationship added to Interactable(BeingInteractedWith, Interactor)
    • InteractableSystem
      • Query: Interactable(BeingInteractedWith, *)
      • Process:
        • For each interactable:
          • interactors = Get relationship targets (interactors) for Interactable(BeingInteractedWith, *)
          • action = Get the Interactable component from the entity and get the action from the component
          • run the action with the correct params and optional meta
            • action(interactable, interactors, meta)
          • if the action suceeded or failed log it out (action returns a bool on success/fail)
        • Reset the interaction state

Definitions

  • Interactor - The Entity that can interact with stuff.
  • Interactable - The entity that can be interacted with.
  • Interaction/Interact - The process of an entity being in an area that allows it to interact if the entity matches against a query initiating the interaction then having an action run
  • Action - The function that is run when an interactable is interacted with
  • CanInteractQuery - A Query that defines if an Interactor can Interact with an Interactable. If the entity does not pass the query they can not initiate the interaction

Components

Relationships

  • Interactor(CanInteractWith, Interactable)
    • Applied to the Interactor when they enter the area and mass the CanInteractWithQuery
  • Interactable(BeingInteractedWith, Interactor)
    • Applied to the interactable when it is being interacted with

Systems

Interactables System

Managed the objects that are interactable validating and performing the action defined on the interactable component of the entity

Interactions System

Managed the interaction between the entity that can interact and the

Examples

Door

Door Entity

  • C_Door
  • C_Interactable
    • Action - OpenDoorInteraction
    • Input Action - "f"
  • C_AnimationPlayer

InteractionArea - Nested under Door Entity

Static Queries

  • SQ_IsPlayer
  • SQ_IsInteractor

Player

  • C_Interactor

Open Door Interaction

All this interaction does is add a single component C_PlayAnimation.new('open_door') to the door entity and the animation system will pick it up and play the animation. Then all you have to do to make doors is create a scene with the above setup and animate an open_door animation and you have reusable door interactions