Character abstraction

Godot Version

4.2.2

Question

I’m making a game about a running race :running_man: , and I wanted to create a scene for a “runner” to be reused for both the player runner and the pc runners.

After separating the code actually moving the CharacterBody2D node to a separate Runner scene, I added it as a child to a Player scene, with the intention of having the parent Player script control player related topics exclusively: camera, player input etc.

Input works fine but I have 2 issues:

  1. I would prefer the camera node will be used as a child of the Player scene and not in the Player scene as a child of the runner, but because the Player core node doesn’t move, only it’s child, this doesn’t work.
  2. Detecting collisions with area2D nodes on the map pick up the Runner class and not the parent Player class.

I’m certain my issue is with architecture and proper node selection and use, just not sure how does a cleaner structure can look like :thinking:


1 Like

You could try inheriting your runner scene (right click in the filesystem) and extending your runner script (right clicking in the scene tree), should clean up that scene tree nicely, less superfluous parent nodes.

1 Like

Yes! Perfect! not only cleaned up the code but also corrected the structure of nodes. thanks! :star_struck: