Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 5)

In this post, I will be adding wall-climbing and sliding.

Today’s Objective: Add the ability to wall-climb and wall-slide to my 2D player controller, so the player can bounce between walls to get to higher positions.

The Code:

I want to allow easy toggling of these 2 abilities, so I need 2 booleans. I also need 2 floats:

Now, since the wall climbing will happen when the player is not touching the ground, I will put most of the code in the AirborneBehaviour method which is called from Update whenever the player is not grounded.

Next I’ve made an If Statement checking if _isWallSliding is true.

Within the Jump method (created in my past post), I simply add the behavior for wall jumps into the existing switch statement:

I close off the behaviour by updating the animations in the event method which is called whenever the player becomes airborne (including jumping/falling from a climbable wall).

If anyone didn’t noticed, since yesterday’s post I’ve added a player model and lots of animations to my game. Looking much better now, isn’t it? More to come though. :)



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
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.