Hi,
I’m still learning, but I already have a small game up and running. I’m currently cleaning up the code and trying to optimize it.
I have a general question for the more experienced among you regarding the overall structure:
-
I have a pickup (root Area2D, outsourced in a scene) that, when touched by the player, emits a signal (for scoring points in the GameManager) and then becomes invisible. This means that the pickup basically manages itself.

-
I have an enemy (root CharacterBody2D, outsourced in a scene) that also disappears when its Area2D collision is touched by the player. Here, too, the element manages itself.

The player (root CharacterBody2D, outsourced in a scene) is now giving me a headache. It has a health variable. This should be counted down when the player touches an enemy (or an enemy runs into the player). If the counter is <= 0, the player should fall off the platform with a given animation from the animationplayer.
Question: Where do I put all the logic for the player?
-
Do I store the player’s health variable in a global GameManager script,
or directly in the player script? -
How should the ‘kill player’ action be handled?
Is it executed from a global GameManager, or is it managed in the player script? Or from the enemy script? Or by a signal? I don’t know! -
What is the best strategy for detecting hits on the player?
Does this happen inside the enemy or in the player script? -
Where does it make sense to give signals (GameManager, enemy, player)?
-
And from where do I check the health value and make the player fall off the platform and start again? There are so many possibilities, and I don’t know which one is the best and most sensible.
Do you have any general structural tips for me?
Thank you very much!
Jeff