Controlling the Player Character in Unity with a simple script

Richard Morgan
2 min readMay 3, 2022

--

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:

--

--

Richard Morgan
Richard Morgan

Written by Richard Morgan

Unity developer interested in AI integrations.

No responses yet