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?
Answer
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.
No comments:
Post a Comment