18
\$\begingroup\$

In my game, I'd like my character to be able to grab and hold onto ledges, and to be able to pull themselves up if there's room to do so.

How do I detect if there's a ledge, and if the character has enough space to climb up?

\$\endgroup\$
22
\$\begingroup\$

The video for Overgrowth Alpha 132 shows how they implemented ledge climbing.

Their method should work in any engine, even 2D engines where you'd use a rectangle and circle instead of a cylinder and sphere.

Their ledge detection involves two parts:

Wall detection (using the sphere)

The game checks if the player's currently colliding with a wall. If there's a wall, there might be ledges the player can grab onto. The second part takes over to analyse the ledges.

Ledge detection (using the cylinder)

If the player's contacting a wall, a cylinder is swept downwards from a certain distance above the player's position until it touches a ledge. This determines three things:

  • Whether a ledge exists above the player
  • The ledge's height
  • Whether there is room for the player to climb up onto the ledge, considering the cylinder occupies the same horizontal space as the player.
\$\endgroup\$
  • \$\begingroup\$ Amazing method, and fantastic example +1 \$\endgroup\$ – Bugster Oct 20 '12 at 12:19
  • \$\begingroup\$ "a cylinder is swept downwards from a certain distance above the player's position" What distance? This is very important when dealing with indoor environments (you'd intersect the ceiling by accident). \$\endgroup\$ – Tara May 17 '15 at 3:13
  • 1
    \$\begingroup\$ @Dudeson in the past I've used a raycast to initially find the ledge surface, before following-up with a volume check to verify that there's enough unobstructed room to climb up. Since the raycast is directional it doesn't read ceilings as false positives - though it could still get snagged on the next floor up if the origin is much too high.. The exact metrics will depend on a lot of particulars of each game - the character size, arm reach, clearance in the level design, falling speeds, etc. \$\endgroup\$ – DMGregory Dec 21 '16 at 16:09
  • \$\begingroup\$ @DMGregory Good idea with the ray cast! \$\endgroup\$ – Tara Dec 22 '16 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.