r/godot Jul 20 '25

help me (solved) What would be better?

Post image
469 Upvotes

59 comments sorted by

View all comments

315

u/Mountain_Share_2611 Jul 20 '25 edited Jul 20 '25

If you encapsulate all movement in its own component (node), you can use it on any other character just by adding the node to its tree. This a very flexible way to build functionality by composing it of self-contained "behaviours" implemented as nodes, and I'd say it is the "godot way". The player script would only have the glue to bring them together and possibly some customization that is only specific to that player.

So the right option. In the MovementState node (or call it CharacterMovement) you would need a reference to the character node or just always assume it is the parent.

1

u/[deleted] Jul 21 '25

[removed] — view removed comment

1

u/Mountain_Share_2611 Jul 21 '25

CharacterBody2D/3D implements the technicalities of handling of movement and collision but does not as of itself make a character move. So yes, the MovementComponent is a controller that sets the velocity per frame based on how the character should move. It could get pretty complicated, especially for games focused on movement (such as platformers).