Character Controller – Update 5th Aug 2018

Development Update 5th August 2018

Sooner than you thought, huh?

After yesterday’s development update, I wanted to start strong with keeping you up to date with CyberThreat’s progress from now on. I also received some pretty great advice from a friend about some tips on marketing, so I’d better follow them! I might not be able to post every day, but I’ll do my best to share what I can when I can!

I’ll try to explain things as well as I can in an understandable way so anyone can get the gist of things, but I’ll be sure to mention the more technical aspects for other game devs and programmers to hopefully follow along with too. We indie developers have to help each other out after all, right?

One of my testing scenes. Ain’t it… uh… beautiful?

Character Controller

A character controller is pretty much what it says on the tin, a way of moving a character gameobject around a scene. Uniy provides a CharacterController component for use right out of the box, with an in-built collider we can modify to wrap around our character.

Up until recently, CyberThreat’s character controller was custom made, meaning it didn’t use this component at all. Instead, it used an array of rays (invisible lines extruding from the character) to detect collisions with other objects. This was an “okay at best” approach since the character would stop quite suddenly when colliding with another object. This lead to an uncomfortable gameplay experience when navigating tighter spaces (eg: Doorways, the horror!).

So why switch to using the CharacterController component? Well it’s much nicer to work with for one! It works really well with only a little additional code to get things working properly. Collisions are handled much better and allow the character to “slide” along collisions rather than stop abruptly. The main trick is getting the movements to work relative to the camera rotation. Once I figured it out, everything else fell into place!

The key snippet of code is this:

Vector3 temp = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Vector3 moveDirection = temp * Time.deltaTime * moveSpeed;
moveDirection = Camera.main.transform.TransformDirection (moveDirection);


Where _controller is the CharacterController. More can be read and understood over on the official Unity Scripting API manual here:

You can see that the move direction is modified to be relative to the main camera’s transform properties. Without this, movement is always in the same direction no matter what way the camera is facing.

Using this, I was able to get a much simpler, nicer character movement controller working. It was useful to have written my previous controller from scratch since I learned a lot about working with rays and collisions, but sometimes it really is better not to reinvent the wheel. And things can always be improved upon!

I hope that little bit of insight helps someone if they need it! It’s only a simple thing, but sometimes the simple things can catch you out.

As always, if you haven’t already, make sure to like the CyberThreat Facebook page and follow on Twitter for more updates!



Practice makes perfect, and I’ll hopefully get better at writing these in time, until then thanks for reading!