A young man standing in front of a building holding a sword.

This demo was made following the Unity 3rd Person Combat & Traversal course by GameDev.TV. This course focused on the state based programming paradigm where each state of the player or an NPC is controlled by it's own class. Each class defines the behaviour when entering and exiting this class.

This allows developers to create classes that are responsible for only one action, without this approach (or similar design concepts) a player/NPC controller class would end up being responsible for patrolling, jumping, guarding, attacking etc.

There is a couple of elements of this design that I didn't like. As the code stands at the end of the course each transition to a new state creates a new state object. This can be easily optimised by caching the state objects (either all at the start of the characters life-cycle or when each new state is required for the first time). If necessary states could be marked at design time as single use for states that are used for specific moments in the game which aren't likely to be repeated. Also each state needs to be able to decide for itself which state it should transition to when it is complete or no longer the appropriate state. I would prefer a design where there is a mechanism in a lower level class which is responsible for state transitions. This way player states such as the basic locomotion, patrol, shimmy along edge don't all have to implement an input detection for jump, the lower level class can detect that the jump input has been activated and transition directly to the jump state.

This course also included a simple mechanism for the player to target an NPC. This needs expanding upon in future work.

You can play the WebGL demo of the controller.