2D Character Controller technical input request.

Hey Ya'll.

I'm not sure how to ask this so I'll do a bit of a ramble.
I've written a 2D controller from scratch (unity). It works a charm and short of fiddling with numbers it works pretty much as expected.

What I am struggling with is that the thing is a damn mess and feels very unmaintainable.
Every time I have to add a feature it get's more messy. What suggestions would you have to help improve it?
Moving to a State Machine approach, or separating more of the functionality into more self contained components?

Here's a link to the C# code page for the controller : http://pastebin.com/WuuN8pEM

I would post a link to a build so you can see it in action but it's chock full of Copyrighted sprites that I use for prototyping and I don't know if I'd get in trouble if I posted it.


  • Separate the functionality into modular components. Have a read on the SOLID principle. Specifically on Single Responsibility

    Build your script components so they can be reused on entirely different game objects without having to be modified.

    In your example split the script into 2 scripts. One that contains all the jumping/wall climbing logic, and one that handles the movement/dash logic. When you want you add new functionality (shoot/fly/etc), create a new script for only that functionality. Ensure that each script is not dependent on any of your other scripts.

    You can then add/remove these separate scripts on any object as and when you need to.
    Thanked by 1FanieG
Sign In or Register to comment.