Passive Ability Pickup Checks

Godot Version

v4.4.1

Question

I’m really new to Godot and programming in general so I’ve been meaning to ask how to make a weapon/ability pickup system. More specifically I want to know how to tell the game what ability I currently have.
For example one ability grants the player the ability to double jump, but because it is always active and usable I (currently) would need to check what passive ability I have every frame and that sounds expensive with having to make ~10 if-checks every tick, so I wanted to ask if there was a better/more elegant solution.

Thanks for your time and help.

Hi!

First of all, doing ~10 checks every frame wouldn’t be that expensive. However, you’re right, it’s far from the best solution and although the performances would not be an issue, the maintainability and readability of the code would be.

One important flaw in your logic is: you’re saying you’d need to check every frame if the player can double jump. Why? You need to check if the double jump ability is available only when you’re trying to perform a double jump. If you’re not trying to double jump, why bother checking if you’ve got the ability?

You may then ask: okay, but what if I need to display in some UI or the player that he has the double jump ability? In that case, you indeed need this visual every frame, but you need to toggle it on only at the frame you unlock the ability.
Something like:

  • Unlock the ability (I don’t know how it’s done in your code, but this is a one-frame logic.
  • Depending on what it is, toggle some visuals, play a sound, change a stat, etc.
  • Then, don’t do anything related to the ability unless when you need it (for instance, the double jump case).

There are a lot of ways you can write a nice code architecture for an ability system. But if you’re new to programming, I’d suggest doing a very simple one as trying to a code too flexible and clean would be hard; keep in mind that you can start with something simple, and cleanup/refactor later on!

Hope that helps :slight_smile:

1 Like