Controlling the Player Character in Unity with a simple script

Let’s build a quick script to give the player control of the Player Character using the Character Controller component. The Character Controller component controls the player by accessing the built-in .Move and .Rotate functions:

First, we need a test environment. Here, to a new scene, I’ve added a capsule to a terrain along with a couple of platforms to jump on:

Next we need to add the CharacterController component to our Player. We can remove the Collider component since CharacterController has it’s own collider built in. Oh, and one more thing. This is IMPORTANT: Set the Min Move Distance to 0. Otherwise, our player won’t be able to jump consistently.

Now create a blank script, add it to our player, and add a few variables:

Let’s get a reference to our Character Controller:

Ok, now we’re ready to make some assignments. First, the inputs:

And some more assignments for movement:

And finally we are ready to use Move and Rotate on our player:

So here’s the whole enchilada for our simple player controller:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Richard Morgan

Richard Morgan

Unity and Flutter developer interested in creating mixed-reality applications.