Custom Character Controller in Unity: Part 5 – Release 1.0.0

Since it seems like school is slowly but surely taking over my life (for the time being…) I figured it would be best to release the Super Character Controller package before I complete the Mario 64 demo project, since at this point an ETA for that is pretty far off.

I have added two ways to download the controller: you can either get a .zip file containing an example project or a .unitypackage of the essential scripts. The example project includes a demo scene with a (very basic) implementation of the Super Character Controller™.

Demo project example scene

Just a blue man in a green world…

Download the Super Character Controller

Regardless of whether you open the demo project or import the .unitypackage, you’ll have a folder containing all the essential code, named SuperCharacterController®. Inside this folder there is: the RPGController folder containing classes used to build Mesh trees written by fholm; a README file, Math3d class (by BitBarrelMedia), DebugDraw class (by me) and finally a Core folder that holds all the character controller classes.

You shouldn’t ever need to touch anything in the RPGController folder unless you plan on doing some rewriting of the mesh trees. Math3d is hugely useful and is widely used inside the controller classes. DebugDraw is a class I wrote to streamline drawing visual debugging cues to the screen, and has some helpful methods that will draw vectors, markers, etc.

Inside Core there are five classes. SuperMath is a static class where I dump any useful math functions I come up with that are not represented in the standard Mathf. SuperCollider is another static class, with it’s only current method being (three variations of) a tool to find the closest point on the surface of a (Sphere, Box or Mesh) collider. SuperCollisionType is meant to be attached to all objects the controller collides with, to allow the user to customize certain properties (at what angle on this surface can the controller stand, slide, fall, what type of ground is it, and so on). This is meant to have additional properties written in (although in the future using some sort of inheritance would probably be better). Currently, every object the controller collides with is required to have this attached.

SuperStateMachine is a modified version of the state machine built in the Unity Gems Finite State Machine tutorial. Mine is a bit more stripped down for simplicity but is still hugely powerful. Having an easy to implement and use state machine is by far one of the most important components of game development, especially when it comes to prototyping character movement and actions. This state machine is written to function exclusively with the SuperCharacterController. Characters that use the state machine are implemented as a subclass of the SuperStateMachine. I typically using a naming schema following the pattern of “CharacterNameMachine.” For example, my Mario 64 project has classes named MarioMachine, GoombaMachine, BobombMachine, which all inherit from the SuperStateMachine.

[ EDIT: The above link previously pointed to, which as of Jan 1st, 2015 displays only “pageok” on it’s home page. As the page is clearly not okay despite it’s assurance, I changed the link to instead point to a web archive of Unity Gems ]

Finally, we have the man of the hour, the SuperCharacterController©™®. In general (or at least initially) you won’t need to do much to this component other than add it to your objects. It broadcasts a message to all other scripts in your object to call a function named “SuperUpdate”, where you can perform all your character logic and movement. Much like the Unity character controller, you’ll probably want to cache a reference to the Super Character Controller in your controller scripts. This way, you can access certain public members (controller height, radius, etc.) and public methods (to disable and enable clamping, ignore colliders, and so on). For a more in depth description, see the example attached to the demo project.

I tried to test this package as much as I possible could, but this is the first time I’ve really distributed a project this large, so hopefully it will work fine on everyone’s different machines and software. If anyone runs into any errors, please post them below as a reply.

And no, SuperCharacterController isn’t actually trademarked/reserved/copytradereservemarked.