Tutorial 4 - Ladder Climbing

Tutorial 4 - Ladder Climbing

Setting up Ladder Climbing in the Graph

Step 1: Elements Involved

For ladder climbing to work, three things play together:

  1. The ladder asset itself needs to be created following certain guidelines. See the Ladders Tutorial on how to create such an asset.
  2. The code in the game dll will position the character on the ladder and update his position and his animation depending on the player's input. This code is in place and you usually won't need to modify it, unless you want to add in support for different ladder types or more enter/exit variations.
  3. The Animation Graph needs to contain animations for the ladder and notify the game code that these are active. Two states are required for this.
    This part will be covered in this tutorial.

Step 2: On the Ladder

Since ladders can be of different lengths, the animation for the character while he is on the ladder will be a looping animation.

  • Create a new state and give it a fitting name.

  • In the Node Details of the new State, choose the "Loop" Preset for the Parameters.
  • The code will update this animation manually each frame if the player is pressing up/forward, so you need to check the checkbox for "Manual Update". This will prevent the animation system from automatically playing back the animation.
  • Assign your climb loop animation to the state.

  • The Code will set the Action input to "climbLadder" as soon as the ladder climbing begins. So in the Selection Criteria of the newly created state, choose the Action input from the Unused Panel, set it to "Specified Value". Then select "<Add Key...>" from the dropdown box. Enter "climbLadder" in the window that pops up and confirm with Ok.

  • If you have an Alive Parent state or similar, feel free to set it as parent for the state.
  • Only the Action Input is required for this state. Your Selection Criteria should now look like this.

Step 3: Exiting the Ladder

Once the character has reached the upper end of the ladder, the code handling the climb will try to trigger an exit animation.

  • Create a new state and place it in the same view with the looping state created in Step 2.
  • Create a link from the Climb to the Exit state.
  • Assign your exit animation to this state.

  • In the Node Details choose the "OneShot" Parameter Settings. This will make sure the exit transition will play uninterrupted.

The animation for exiting the ladder will transport the character off of the ladder, so it needs to be in control of the character's movement.

  • To enable this, select the "Movement and Physics" Tab on the right side of the Node Details panel.

  • Choose "Animation" for both the horizontal and the vertical movement control methods. This will allow the animation to actually move the character.

The code will trigger the animation by setting the Signal Input to "exit_ladder_top".

  • Select the newly created state and go to the Selection Criteria on the right.
  • Bring the Input "Signal" up from the Unused (or Inherited, if you are using a Parent State that defines it) panel by setting it to "Specified Value".
  • Just like with the Action input in Step 3, add a new key to the input and call it "exit_ladder_top".
    Your selection criteria should then look like this:

Step 4: Telling the Code that Ladder Animations are playing

In case something goes wrong with the animation or no ladder setup exists at all, the code will query whether the graph is still in one of the ladder states. If it is not, it will exit the ladder. This is also the reason why ladder climbing doesn't work if there is no AnimationGraph setup for it. The code uses the feedback from the graph also to determine when the exit ladder animation has finished.

To check whether the code is in a ladder state, the graph has to set an output which will be queried by the code.

  • Go to the menu Graph -> Add Modifier -> Output to add a new Output Modifier.
  • In its Node Details type "OnLadder" as the Output Name, and "1" as the value it is to be set to.

  • Place the modifier in the view with the two animation states.
  • Link the modifier to each state.

The Ladder Climbing setup is now complete. You can save and reload your graph.

  • If you need to debug the ladder climbing, please see the ladder entity's documentation for debug console variables: Ladder Entity - CE3.4 (deprecated)
  • To adjust the character's position/animation on the ladder, see the console variable "pl_ladder_animOffset" as described in the Ladder Entity's documentation.