#How would you create an item system that grants an effect on pickup?

2 messages · Page 1 of 1 (latest)

night zephyr
#

Hi, I'm having a dilemma choosing the way I want to create my item system.

The question:
How would you set up your item system in the matter of having it picked up and then having that item granting an effect to the character (ability to shoot, jump higher, etc.)? Think about it as a mario bros game. You pick up the flower, it grants you the fireball shooting ability.

In my case, the item will go into an inventory and their effects activate by using a certain button (so yes, similar :D).

This problem can be solved in many ways, but I'd like to get some opinions on it and "why" you choose a certain way to do it. I'm looking for a "best practice" (if there are any for this).

My idea's that hang around:

  1. One "main item" node that contains all functionality (pickup functionality in a child node and also knows which effect to execute in another child node). When this item is picked up, it will hide the node and extract the item into the character's inventory. From this point on, it will be hooked with the player actions. Resources used where possible.

Visually something like this:

MainItemNode
- PickUpItemNode
  - Sprite2D
  - Area2D
    - Collision2D
- FireballItemNode

ItemEffect will be moved into the player's inventory, which knows everything how to use, the name, etc.

The MainItemNode has a script that controls both of them and uses the resources to fill in data.

  1. A separate pickup node that contains resource data and some logic to have a character pick it up. On pickup, the resource knows what item node to transfer into the inventory and will hide or destroy this item.

  2. Something I didn't think about and that you can introduce me to? 😄

If something is unclear or if I missed out on something feel free to ask!

I appreciate your time for this!

dire tapir
#

It depends, is it only the player who can activate these effects or can NPCs also? If only player then put the logic inside the player scene. Make a separate node with a script for PickupItems.
Make all the pickups in one scene where you have an @export ENUM that controls which kind of pickup it is. Then it is really easy to manage in the Player-script.