Search Unity

Ledge climbing

Discussion in 'Getting Started' started by witcher101, Dec 13, 2015.

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    Hi can any1 tell me concept behind ledge climbing and how its done.
    I mean the way its done in tombraider. How do you hang from ledge and how to climb

    Thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well, you have data structures (usually a navigation mesh, which could be a Unity NavMesh or your own structure) that defines the surfaces you can walk and climb. You have a state machine that controls the avatar state and its animations. When you're in the jumping state, and possibly when some action or grab input is pressed, you check to see if there's a walkable surface within a certain distance above the player. If so, then you transition to the "grabbing ledge" state, which does an appropriate animation, and then transitions to the "hanging from ledge" state. At that point, normal control inputs switch you to the "ledge-shifting left" and "ledge-shifting right" states, which do what they should; an up input goes to the "climbing up onto ledge" state and animation, etc.

    There's really nothing about it that's different than any other character animation & control. It's just a bit more complicated. (These state machines can get quite hairy, though using hierarchical state machines can neaten them up a bit.)
     
    Martin_H likes this.
  3. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    Thanks i will need to try this and see how it goes;)
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The primary problem with ledge traversal is knowing where the ledges are. You can't climb what doesn't exist in your code.
     
    JamesArndt and Martin_H like this.
  5. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    The way I've tackled this in the past is to place trigger collision along ledges that will be traversable. I have a small trigger sphere attached to my player and when it comes into contact with the ledge trigger I can then attach the player to that ledge (usually with a transform.parent). The player will visually stick to the ledge, and then it's just a matter of creating animations for moving along a ledge and/or climbing up and over it. Once the climb over animation is completed use a triggered event in the animation to detach the player from the parent ledge transform.