Game Creator comes with a built-in interaction system that lets characters (both Players and NPCs) dynamically focus on a scene element and decide whether to interact with it or not.
Interaction when busy
It's important to note that a Character that is Busy cannot interact with Interactive elements.
How a Character interacts with scene objects is specified in the Motion unit.
The Radius option determines the minimum distance an object has to be in order for the character to focus on it.
The Mode option allows to determine how to prioritize how objects are focused:
- Near Character: Picks the closes object to the character's interaction center, which can be offset by a certain amount. This option is best for console and games that require a controller.
- Screen Center: Interactive objects closer to the center of the screen have higher priority. This is the best option for first person games.
- Screen Cursor: Interactive objects closer to the cursor take precendence. This option is best for point and click adventures.
The character will automatically focus and unfocus any interactive object. To interact with the currently focused object, use the Interact instruction.
Any game object with the On Interact event on a Trigger component will be automatically marked as an interactive one.
This event will be fired every time a character attempts to interact with this trigger.
If a character attemps to interact, but there is no Interactive object available, it will simply ignore the call.
Detect new Interaction
Apart from the On Interact event, one can also detect when a Trigger becomes focused or loses focus (also known as blur). This can be tracked using the On Focus and On Blur events.
Hotspots can also display a text or activate a prefab when the game object is focused by a character. To do so, you can add the Text on Focus spot on a Hotspot component and it will display the chosen text every time the selected character focuses on this interactive element.