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

Short-Circuiting (&& ||) and Nullish Coalescing Operator (??)

A Guide To Handling Internet Disconnection In React Applications.

Nullish coalescing operator (??) in JavaScript

Publish and receive Google Pub/Sub message in Node.js

An introduction to writing tests using Cypress

Foundation 6.5.0 Released

JavaScript Arrays Reference Cheat Sheet and Breakdown — Mutating Methods

Let’s learn how to install and setup AngularFire2 4.0

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

Creating Elevator in Unity — Part 3: Moving Elevator.

Using Signal Emitters in Timeline to Alter Playback — Unity

Using Light Probes in Unity’s HDRP

Modular Health System in Unity!