I’ve been experimenting with different design patterns(?) for my player code and I’ve been considering using composition because I really wanna try to keep things modular especially since I plan to add enemies so I wanna be able to reuse some things.
The issue is I think the way I plan to use composition is incorrect. First of all my understanding of composition is it’s basically a bunch of mini classes to make one big class so with that in mind my plan is to have a player class
function Player.new()
local self = setmetatable({},Player)
LocalPlayer.CharacterAdded:Connect(function(character)
self:OnCharacterAdded(character)
end)
LocalPlayer.CharacterRemoving:Connect(function(character)
self:OnCharacterRemoving(character)
end)
if LocalPlayer.Character then
self:OnCharacterAdded(LocalPlayer.Character)
end
RunService.Stepped:Connect(function(dt)
self:Update(dt)
end)
return self
end
And then add classes that make up the player so player input, movement, dashing, jumping, evading, etc so I’d end up with something like this.
function Player.new()
local self = setmetatable({},Player)
self.Input = Input.new()
self.Movement = Movement.new()
self.Combat = Combat.new() -- or maybue just self.PrimaryAttack, self.SecondaryAttack, etc
self.Dash = Dash.new()
-- etc
end
Not sure if this will end up causing issues though so looking for some advice.