Creating a Physics Based Character Controller in Unity

Objective: create player movement with the character controller component.

Usually when we want to work with physics in Unity we use the rigidbody component and Unity provides a lot of methods like addForce that make the physics implementation easier. In this case for educational purposes I am going to use the character controller component and some of the physics have to be implemented manually.

So the first step is to add the character controller component to the player and create a new script for the player.

In the script I created a variable for the speed and another for the handler of the character controller component. In the start method I get the reference to the character controller component using the get component method.

In the update method I got the horizontal axis value and created a vector3 variable with this value in the x axis. Then I used the function move on the character controller and passed the vector3 multiplied by the speed and the real time.

And that’s it!!! Now we have the player movement ready.

--

--

--

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React Konva Performance Tuning

I Chose TypeScript For the Nostalgia

Best (and worst!) ways to center WITHOUT flex or grid

Expressjs middleware

React js

How You Should Not Write JavaScript

Best Practices for Building JavaScript SDKs With TypeScript

Control Flow and the Progression of Asynchronous JavaScript

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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

More from Medium

Player Jump in Unity

Day 102: Character Animation Part 5

Adding a thruster speed boost on keypress

2D Shadows in Unity — Shadow Caster 2D Component