I’m working on making my own player and character code with OOP and I’m struggling a little bit with how I can get my input code to communicate effectively with my character code for movement and other actions.
This is my player class which just handles creating a new character and updating the model reference with the new character when they respawn.
function PlayerClass.new()
local self = setmetatable({},PlayerClass)
self.character = BaseCharacter.new()
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
return self
end
function CharacterClass.new()
local self = setmetatable({},CharacterClass)
self.model = nil
self.health = 100
self.walkSpeed = 16
self.jumpHeight = 7
self.maxJumps = 2
self.state = nil
return self
end
function CharacterClass:SetModel(model)
print("CharacterClass:SetModel()")
self.model = model
end
function CharacterClass:LockOn()
print("CharacterClass:LockOn()")
end
function CharacterClass:Dash()
print("CharacterClass:Dash()")
end
function CharacterClass:Evade()
print("CharacterClass:Evade()")
end
function CharacterClass:Jump()
print("CharacterClass:Jump()")
end
Now my input code is just a torn-down version of the control module in the player module and I keep trying to do an inheritance approach, but it feels clunky so wanted to know what else I could do.