In my previous projects I usually wrote my input code with the rest and of my player code, however, after using unity for the last couple months I’ve learned that you wanna try and break things up to help decouple your code and so I found that writing input in a separate script is good. The question is what’s a good way to communicate to other scripts what was pressed? My guess is to use events and just have whatever scripts that care about input like the player script listen for it and then check a table to see if that input is assigned to an action and then do that action. My guess is probably the worst approach so looking for advice.
Usually I wouldn’t make something like that sinve you are just complicating the process, but if you really want to achieve it, u can take a look into sleitnick’s rbxutio module which has an Input module, a pretty good one as far as modules go imo bjt nonetheless lmk if you want smth else other than the one I suggest.
I would advise against this, BindableEvents are horrible and should totally be avoided when there are better options like GoodSignal.
You think handling input in a separate script will over complicate things? How so?
That sounds like context action services which should work just fine tbh.
As long as you can separate the functions and the actual input binding code with the interface to CAS or UserInputService it should be good and follow composition based programming.
For my current system I have a class and component classes
The component classes can have a :Update(moveDirection, dt), InputBegan, InputEnded function.
The overall class PhysicsCharacterControllers just handles creating all the component classes, storing them in a table {} in itself as a property,
It also has a function to loop through them to execute the :Update() and does the binding for the InputBegan, InputEnded.