Interactions
Overview
The InteractionsSystem
provides a mechanism for interacting with other entities.
Setup
There are two ways to implement an interaction, either through direct interaction relying on IInteractableObjectController
or using a trigger collider relying on IInteractableTriggerController
; these approaches can be used separately or in combination with each other.
Interactable Object
IInteractableObjectController
is implemented by the interactable object's entity controller. Returning true
in the Interact()
method means the interaction was successful.
C#
public interface IInteractableObjectController
{
bool Interact(Frame frame, EntityRef entity, EntityRef instigator);
}
Any entity with an Interactions
component can then interact with it by:
- sending an
InteractCommand
(Player); or, - setting up properties in
InputDesires
(AI).
Alternatively, InteractionsDesires
can be set up directly.
Interactable Trigger
To create an interactable trigger, the object has to have a trigger PhysicsCollider
and its entity controller has to implement IInteractableTriggerController
. Any entity with a non-trigger PhysicsCollider
AND PhysicsBody
can step into it.
C#
public interface IInteractableTriggerController
{
bool OnEnter(Frame frame, EntityRef entity, EntityRef instigator, TriggerInfo3D info);
void OnExit(Frame frame, EntityRef entity, EntityRef instigator, ExitInfo3D info);
}
Returning true
in the OnEnter()
method means the interaction has been successful. A list of the currently interacting instigators (entities) can be obtained from the InteractableTrigger
component. OnExit()
is called when the entity (or all its subparts) has moved out of the trigger volume and has been removed from the list of instigators.
Example
The Door found in the PLAYGROUND_Interactions
scene present several interactions. For instance the DoorController
implements the IInteractableObjectController
interface. However, instead of interacting directly with the door itself, agents interact with a button which in turns triggers the interaction with the door. To enable this behaviour, it uses the Interactable Button
component and is connected to the DoorController
via its SignalReceivers
list property.
The InteractableToggle
component works in a similar fashion.