Ledge Grab Part 1

Objective: Create A Ledge Grab in Unity

Currently our Player can run and jump to the ledge but he remains in the above transition. We need to fix that by allowing him to grab the ledge. As like with the other animations, we go to Mixamo and find the aniamtion we want to use.

We do the usual import, change rig to humanoid, duplicate animation, put it in the animations folder, turn loop time on and bake into pose.

We will use a cube object with a trigger as part of the Player to use for a trigger. There will be another cube object set up to act as a ledge trigger check when the players trigger cube hits or collides. This will then be used to trigger the ledge hang animation and logic for the Player to hang from the ledge.

We will fix the position of the trigger objects later once the code and animations are working. Create a script for the ledge and attach it to the fixed cube trigger. Add a Rigidbody to the Players cube as one of the objects colliding needs a Rigidbody for the OnTriggerEnter to work. Inside the Player script, move all the movement logic from the Update method into its own method called CalculateMovement and call it in the UpdateMethod. We will turning off the Character Controller on trigger so we will run an if statement to check if the controller is enabled before running the CalculateMovement method.

Next we need a public function for the Player to grab the ledge and this will take in a Vector3. This Vector3 will be the Players position when hanging on the ledge.

Move in to Ledge script and create a serialized Vector3 for the Player ledge position. We can find this through the scene view by moving the Player into place taking the transform positions and then entering them in the Inspector as values for the Vector3. Next we need an OnTriggerEnter and check if the other tag is the ledge. If so get the Player using other transform parent GetComponent and null check before called the Player class method GrabLedge and passing through the Player ledge position.

Next set up the transition between running jump and hanging idle in the Animator. To do this we add a bool parameter of grabLedge and when true transition to hanging with no exit time, no fixed duration and 0 transition duration.

Back in the Player script, inside the GrabLedge method we can now set the controller to disabled, trigger the ledge grab animation and set the Players position to the Vector3 values that were passed through.

In the next post, we will get the Player to climb up from the ledge.

--

--

--

Developer

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

Recommended from Medium

José Valim: “Elixir is great for everything that runs on top of a socket”

Advance Color Quantization with Camalian

SSLForFree Partners with ZeroSSL — New Guide to Install Free Certs

SSl for free and zero ssl

Improving Apache Spark performance on k8s

Running a GUI on Docker Container

Flutter: Lazy Loading on Scroll Made Simple

The Ultimate Guide to Linting

The Poison Pill Process

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
Simon Leen

Simon Leen

Developer

More from Medium

Ledge Grab System: Part 1

Adding another powerup — Shields

I think you dropped something — Creating a simple loot drop system in Unity2D

Script Communication in Unity Using GetComponent<>