2.5D Platformer — Ladders #11

What a thrill…

Another addition to my Platformer project is Ladder Climbing! It’s not as thrilling or fancy as other games that properly aligns the hands and feet to the handles of the ladder, but it’s a “decent” start.

“Decent”, you say.

It’s okay… well no, it’s cheap and hardcoded, but coding a first iteration first hand lets me know how I would proceed to make something more polished. And sure, this implementation would work best for something like vines or other believable surface that doesn’t require matching the position of the hand with an object. But hey, I hope at least that you can too make something out of this article and do something greater yourself.

Now here is where my implementation would work best!

How does my implementation work?

To begin with, I added a new state to my character controller, which is “On Ladder” and two booleans to check if the controller is climbing a ladder in the current moment (isLadderClimbing), and if it is finishing the ladder climb (isLadderFinishingClimb).

The states help me handle the different behaviours between each state, and process every transition easily. You can do it however you like though.

I also made a new script for the ladder, which I’ll use to give information about that particular ladder to the controller. However, I’ll need two variables more to store the nearby ladder and the one the controller is currently climbing.

And another one for the climbing speed.

For the Ladder script to work, the Ladder GameObject requires three additional components:

  • One or more collider triggers to assign the nearby ladder through OnTriggerEnter, and deassign with OnTriggerExit.
These two colliders are in the same GameObject, and they all trigger OnTriggerEnter
  • One Empty child GameObject with a collider attached which serves as the travel bounds of that ladder. This is where the hardcoded stuff makes their way into the feature, and for every different ladder, you may have to adjust it for it to work as intented. Pretty bad, but it’ll do for now.
I’ll explain later on why the travel bounds are so small and important
  • Another empty GameObject to adjust a upwards position for the controller. If the controller leaves the Y max bounds of the travel bounds, it will play a climb animation and that requires teleporting the player to a position that matches the ending position of the animation.
Though you could skip this step if you reference your character’s right foot, and teleport the controller to the position of the foot. Anything works really.

Once the player controller enters one of the triggers of the ladder, the ladder script will pass a reference to itself and that way, the controller will have all the information it needs to start climbing the ladder.

Instead of making the variables public, create two new methods of return-type to get both the Upward TP Transform and the Ladder Travel Bounds to avoid any possible mistakes such as clearing the value or changing it accidentaly
Mid-way through the article, I finally noticed how badly the variables are named. Anyways…

Now that the controller has a way to know if it has a ladder nearby, we need to add an input to start climbing the ladder, changing the position of the controller to move it closer to the ladder, setting the new State to OnLadder, and so much more. Because there’s too much to actually explain, I’ve commented the entire Ladder Check for you to read.

Hopefully, you understood what each line of code does

Once the check is done and the controller has set its state to OnLadder, it’s just matter of moving the controller vertically, and checking if the player wants to jump from the ladder, if it touched ground again to leave the ladder, or has reached the top of the ladder.

LadderEndClimb() just removes the reference to the ladder and resets the isLadderClimbing to false, allowing the Controller to change it’s state to Grounded or OnAir.

And there’s a special method called LadderEndClimbAnimation(), which is called by another script when a Ladder animation has ended. This is used to move the controller to the top of the ladder.

Result

It look, as I’ve said, decent. But it’s so disappointing from a code standpoint. Requiring to adjust manually each ladder is just going to lead to more hardwork in the long run.

However, now I have new ideas on how to improve it or scrap it for the “flexible” approach, which is defining the steps in the ladder and let the animation do the work for you (Dark Souls style).

Prototyping will give you enough insight which will allow you to grow your skills further. That’s how you climb the Game Dev ladder. :)

--

--

--

Junior Unity Developer

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

Recommended from Medium

[Algorithm] Longest Common Substring (C++/DP/Medium)

Preparation for AWS Certified Data Analytics Specialty

Using the MiniFrag Database to validate your SMARTS strings

Semantic Commit Messages with Emojis

Roaming Without Stability — Where Roam Could Be Improved

Version control systems and Git

Finding the Percentage of Missing Values in a Pandas DataFrame

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
Pablo Gómez Platón

Pablo Gómez Platón

Junior Unity Developer

More from Medium

In this article, we will look at the Cronos network and its key indicators that this network has…

Worth The Wait — In Gold!

TSP G-Fund, Could it be Shrinking Your Money?

The “Crypto” show will go on.