Existing Controller
Jack originally made the physics controller and I did some refactoring of the interaction system into a base class for use in our other controllers.
Navmesh Point and click
We already had the game set up to use a phjysics based controller, and so the terrain already had colliders. I used Camera.main.ScreenPointToRay(...)
and Physics.Raycast(...)
to get the point clicked on the terrain, and then using NavMesh.SamplePosition(hitPosition, ...)
I had a point on the navmesh closest to the area that was clicked. This also meant that clicking on a wall/interactable would move you to it, this wasn't desirable in out case so I disabled that by moving walkable terrain onto a walkable physics layer and filtering against that.
Controller Animation
We had no link to the animator from any of our controllers, so I used the base class to pass standardised movement information into the animator giving us animation parameters for all our control options.
Mecanim and Mixamo
Mixamo has a nice array of quick to implement animations, so I picked a few and connected up a blend tree (left/straight/right) for walk and another for run, with a speed based transition. I also added transitions for jump/fall but we removed that from our game.
Tweakables
Since the NavMeshCharacterController
uses a NavMeshAgent
its speed is set on the agent, to allow tweaks from our own class I exposed properties on the controller that would modify the settings on the NavMeshAgent
when the values were changed, such as speed and turnrate. This meant that we could use a unified API accross each of the controller classes.