Mantle/Ledge grabbing system

Creating a mantle system similar to that of Destiny 2 using animation motion warping.

Introduction

This article expains how the mantle system was implemented using a mix of collision tests, traces and UE5’s motion warping plugin.

Final result of mantle system. Shows both short and tall mantle, in first and third person and also demonstrates different edge cases in which the mantle system does not activate such as when theres not enough space to perform a mantle or if the player is not looking toward the mantle surface.

Ledge mantle system in Destiny 2

One of the main improvements that Destiny 2 made over the original game was adding a mantling system. This system works by automatically climbing on to ledges and platforms, greatly improving the game feel when trying to do platforming puzzles (a main section of some levels in the game). Many games have a dedicated button to mantle onto ledges, however Destiny 2 uses a simpler method of activation for the mantling system. The criteria to activate the mantling system are the following:

Once a mantle is activated, depending on the vertical distance to the ledge, the player will perform either a short hop animation or a proper mantling animation in which the players left hand ungrips the weapon and moves to simulate placing their hand on the ledge.

Mantling system

In my project, the mantling system is mainly done in blueprints. On the player characters Event BeginPlay, the MantleCheck Event is bound to the On Component Hit delegate of the players capsule component:

Weapon Init function

Once a collision is detected, the mantle check event first checks if the other actor in the collision is a Static Mesh Actor and then performs condition checks to see if the requirements for mantling are met. The main three checks done at this stage prevent further mantle operations such as line trace and collision checks from being carried out on a collision with a static actor in which the player isnt allowed to mantle in the first place.

Mantle Check function start

The IsMantling bool prevents a mantle from starting if the player is currently mantling. The CanAttemptMantle function is a custom function in C++ that comes from the custom CharacterMovementComponent which returns true if the player is airborne and currently pressing the move forward input key. Finally RecentlyJumped is a bool that is false for the first 0.5 seconds after a player jumps. Since the jump key event is only registered on the player client, in order for the RecentlyJumped variable to be the same on the server and client, a reliable RPC event is used to set the value of RecentlyJumped from the client on the server player character as well:

RecentlyJumped Server/Client RPC system. `On Grounded Jump Triggered` gets called from C++ when the player presses jump key and is currently on the ground

Collision Traces check

Once the initial conditions have passed, the main mantle algorithm performs line traces from the facing the forward direction of the player to check if mantling can be performed. A total of 5 line traces are performed (this number can be changed for more or less precision at the cost of performance). To begin, an initial line trace is performed from the top of the capsule forward. If this trace hits something it means that the mantle cannot be performed and the mantle check exits out early without the need to perform more traces:

Performs an initial line trace at the top of the player's capsule. The MantleLineTrace function performs a line trace in the actors forward vector direction, starting at a given ZOffset from the actors origin.
Mantle line traces are performed from the top to the bottom of the capsule. Once a line trace returns no hit, the rest of the traces dont need to be performed since an empty space for a posible mantle has been detected and additional checks can be performed from there

Once once of the line traces for the mantle are confirmed to be valid, we check if the player is facing the correct direction and set the player to be uncrouched to ensure that the following clearance check isnt affected by the player capsule being smaller because of crouching.

Then a clearance check is ran on the expected mantle location. If there is not enough space for the player character, the mantle will not trigger:

Clearence check and example using debug setting on the line and capsule trace

The final step before handling the mantle movement and animations is to set the final mantle position variable and to decide wether a short or a tall mantle animation is needed:

Movement using motion warping animations

The main movement of the mantle is performed using Unreal Engine 5’s motion warping plugin. This plugin allows syncing animation root motion to end up in specific positions and is extremely usful for a task such as this one. For each of the mantle types (short and tall), a third person and first person character animation is needed. The motion warping is driven by the third person animation, as this animation will paly on both the client and the server, while the first person animation is cosmetic and thus client only (since the client is the only one that can see first person animations)

Mantle third person animation. Root motion is disabled in the video example to ilustrate the motion of the animation.

The motion warping is divided into two sections inside of the animation montage, one for the vertical movement the character does to get to the ledge and another for the horizontal movement to step onto the ledge:

With the motion warp set up on the animation montage, the next step is to set the warp targets for both the vertical and horizontal movement just before playing the animation:

The final step is playing the correct mantle animations. If a tall mantle is needed a final check is done to see if the player is looking in the general direction of the ledge. Then the movement mode of the player is set to Flying while the vertical motion warping is playing and the variable IsMantling is set to true until the animation finishes playing. If the player is locally controlled, the first person animation also plays:

Play animations mantle animations. The upward execution lines go back to the start to break out of the trace for loop.

Improvements to be made

Back to top

Back to project