Falling in Unity: Physics based Character Controller

Whether you want to fall, bounce, or fly in Unity it all has to do with Physics. Unity does have its own physics system in the form of gravity and other things however for my new project I wanted to try making my own in code via the Character Controller component.

With my scene setup and a Character Controller attached to my player it was time to go into the code.

With the correct variables in place I set out to make a movement system using the character controller. Still similar to the previous games, I had the additional benefit of using the Character Controller’s “.isGrounded” which would but true or false depending on if the object was grounded or in the air.

With this I could easily create logic concerning aerial movement and also restrict jumping itself if I have already jumped.

The Character Controller also bring with it “.Move” which takes the velocity I created via GetAxis and converts it into movement.

In the end we have our basic movement system!

See you next post!

--

--

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