Need help with architecture and scripts

Godot Version

4.2.2

Question

I am working on a 2d side scroller souls-like game. Kind of like salt and sanctuary or hollow knight, that kind of game. Anyways, I am running into issues with the architecture of my project as I am adding more complex things (at least complex to me) such as a health bar and stamina bar to keep it simple. The way I have this set up is the player starts at a loading screen


Then is brought to a class selection scene

This connects to a sqlite database I have to pull in the attributes for each class etc etc. Each of these classes is it’s own scene.
image
Once the user clicks start. based on the class_id of the class button clicked, that scene is instantiated into the “World” scene which contains a camera, the tilemap. the progress bars and a spawn point
image
I have already run into issues with linking the camera up to the character as I have the camera in the world scene and I link it to the character once instantiated.

Basically my question or TL:DR. I am dynamically instantiating my characters into a scene. Is this the right way to go about this problem or is there a smarter way. Also, as a side question, should I have the same script for movement/attacking for all characters or a separate one for each.

Any videos/links/documentation is greatly appreciated as I am pretty stuck moving forward

Good question. You want to take a structured approach to your gamedev. I respect that.

What you could do is:
Under your Node2D create a player node with a basic script and add the camera as a child. The player node has basic movement code and not much more. Then, instatiate your class node as a child of the player node and have that control the player behaviour. This is a composition approach. A composition tutorial can be found here: https://www.youtube.com/watch?v=JJid46XzW8A. For example, you can give the player node an attack function that in turn calls the attack function on your class instance (which is a child of the player).

Alternatively, create the player node and add the camera as a child to the player node (as before). Next, you can use the state machine approach to control which class the player is using at that time although this might get complicated if you need more states then just the class states.