Concepts
Interactions
How characters interact with objects.
As players move around in a game, they have to be able to detect when they're near an object they can interact with. For example: A player character walking up to a storage box, which they can open in order to access its contents.
This is the responsibility of the Interactor
and Interactable
component pair.
These two components operate in diegetic world space.
In other words, they're 2D/3D specific.
In a 3D game, it's common to let the player aim at an object they want to interact with using a RayCast3D
.
The Inventory System does not currently include 3D interaction components.
2D Components
In 2D games, it's often sufficient to make interactions available by proximity.
This is achieved by detecting when Area2D
objects overlap.
Interactor2D
The GGInteractor2D
component is added to a character to detect when that character is within range of an interactable.
Interactable2D
The GGInteractable2D
component is added to any object that a character can interact with.
It has two purposes:
- To be able to be detected by a character's interactor component.
- React to the character requesting interaction, which is determined by the strategy it is configured with.
Interactable2D Strategy
When a character interacts with an object, the interactable's GGInteractable2DStrategy
class determines what happens.
For example:
- When interacting with a lamp, the character toggles the light switch to turn the light on and off.
- When interacting with a storage box, the character opens the Inventory Transfer screen to exchange items.
For 2D games, the GGInteractable2DStrategyInventory
opens the object's inventory so that items can be exchanged.