Hello,
First of all, I am an experienced solo unity dev but new to Godot. I am trying to make my player (a state machine based player ) get followed by NPC then if the player dies, NPC becomes controllable via keyboard/controller. I have been struggling to figure out which is the most scalable way to implement this architecture, as I am also intending to make the player state machine grow by adding more states later ,(and by consequence, NPC should also have access to the same state machine). I was planning to use composition, but godot's 's way with aggregation makes it a bit difficult with only one script allowed per Node. In Unity, I believe this would be solved by making the NPC composable and implement an interface that adds the player functionality when the player(or array leader) dies and observer pattern (signals in godot).
The problem is I am new to Godot and still learning my way around it, but I am still unsure how to make the entire architecture described in the title while accounting for possible scalability issues.
What I thought of on the top of my head.
make the npc and player share one parent class named Entity but different state machines then implement move /jump and rest of the states separately, the problem is once the player dies this becomes an issue to pass control from NPC to player, I am not sure how i'd implement it in this case...
use Resources? I am not sure, but as , per docs, that resources can accept a script at runtime, which made me think of slapping a Resource on all entities (same parent class) and in a manager class, manage the entities by giving the first element of the array the player script (with input) and the NPCs their AI script, once player dies, the resource on the next element of the array gets the player script while freeing the dead player. is this possible?? I am not familiar with Resources but this sounds like godot's version of Scriptable Objects.
I read somewhere about using virtual Input architecture? which would be nice to keep changing between a player/npc, but not really my use case. I am not familiar with this either but I wonder if anyone knows anything about this and if it applies to my use case.
This is the first time I am encountering this use case and if it were just player + npc follow i'd do it, but passing the control is where I am a bit hazy about it. In unity composition is possible by adding multiple scripts to the gameobject, in Unreal, it literally has a possess pawn class that helps with this, but in godot...I am not sure how to do it. I would love to have your input and advice.
Thank you for your time and help!