MindVisceral / EZGame

1 stars 0 forks source link

Basic Player-Level interaction #26

Open MindVisceral opened 10 months ago

MindVisceral commented 10 months ago

Besides shooting and movement, the Player and the Level don't interact in any way

This should be changed with the addition of, for example: -doors, -ladders, -elevators, -switches, -pickup-able items, -pickup-able weapons, -pickup-able (throwable?) objects

First, a Node similiar to a Hurtbox must be created. This Node will handle each specific item's interaction with the Player (and AI?) This system may be expanded from that point forward

MindVisceral commented 10 months ago

Implementation idea:

Each Object that is made interactable (does something through its script when it is interacted with by an Entity) has an Interactable Area3D node added as its child. This Interactable's InteractableRange detects when an Entity enters it, and adds the interactable Object to that Entity's InteractionManager's "interactables" Array.

From that point, the Entity may decide to interact with the closest Object by calling its unique interaction functions. The Player, besides withing being in the range of the Object (within InteractableRange Area3D), must also be looking at the Object (Interactable Area3D itself). Only one object may be interacted with at a time.

MindVisceral commented 9 months ago

Whilst working on DuckGame, it came to my attention that the current implementation sucks a little. The Player should only check for Interactables within range when the input_interact button is pressed. There is no point in checking for Interactables every frame.

To counteract this, a secondary Area3D which checks if the Player is within range was added. This design, when actually used to work on the levels, turned out to be very annoying to set up. This implemetation is simply not worth it. I order for it to be reworked as per #27

MindVisceral commented 9 months ago

As of 2024.2.15, the day on which #27 was finished and marked as Closed.

The Interaction system in its current form works like this: An arbitrary Node referred to as an 'Object' is created. This Object carries functions which are called when this Object is interacted with by the Player. An Interactable Area3D Node is instatntiated as a child of this Object. When the Player looks at this 'Interactable' Area3D, it is detected by the Player's InteractableCast, which then makes it emit either the "focused" or "unfocused" signal. The purpose of these signals is to visually tell the Player which Object in their vision they will Interact with upon pressing the "input_interact" button. The code which makes this clear to the Player is located in the Object's script; typically an Outline Shader is made visible. Simultaneously, if the Player presses the "input_interact" button, the Interactable node will emit the "interact" signal, which the Object uses to perform an arbitrary purpose, like opening a door or turning a light on/off.

That is the basic purpose of this system. With that done, now actual Objects may be implemented.