2D Climbing with Raycasts

Godot Version

4.2.2

Question

I have a climbing mechanic where you can climb on any ledge. It works but it looks pretty weird (Character grabs in the air etc.). Is there any other way of detecting a ledge without having to go through each ledge in the game adding some sort of detection thing? Right now my raycast cycles through -90/90 degrees and -120/120 degrees to detect a ledge. If the raycast detects something at 90 degrees but not at 120 degrees it will make the character hang on the ledge. (Obviously, there are other checks in place to detect climbing like seeing if the user is in the air, etc). Should I make the raycast cycle through more degrees or is there an easier way to do this? Thank you for reading this.

How big is the raycast2D?

I made the Raycast pretty skinny. I am now going to cycle the raycast through many different degrees to get a more accurate climbing position. Hopefully it goes well haha.

One way I found very effective to detect ledge is to use 2 raycasts.

The setup is having both raycasts stacked on top of each other at the head of the character facing forward with a little y distance between them.

If the the character is in air/falling and the lower raycast is colliding while the upper one is not, then there is a ledge. If both or none is colliding, then it is not a ledge.

Hopefully you get my explanation.

I did exactly that but I used only 1 raycast. I cycle through 90 degrees and 120 degrees to detect a ledge. If 90 collides but 120 does not then it’s a ledge. It works great but the character sometimes floats above the ledge. I think I’ll just keep it until I find something that works really good.

To detect a wall I just use the one raycast set to right, it allows jumping to the wall and when the player changes direction, I flip the raycast as well using the scale command.

When on the wall - I use a bool, and stop all movement in the y direction, then use an animation (arrow buttons) to climb up/down and or jump from the wall to another wall or fall off if you choose. Wall-sliding is a pet peeve of mine.

Ah, I have wall sliding as well. It works ok, sometimes it can be pretty satisfying though. My friends love it.

I am going to change the raycast’s y position instead of rotating it. I’ll update if it provides more accurate ledge detection.

I think changing its y position provided me a more accurate climbing on any ledge method. :+1: