Climbing ledges on moving platforms with move_and_slide() in 2D

Godot Version 4.0

Question

Hey guys, how do you get ledge climbing to work on moving platforms in a 2d sideview game?

In my game, the player can climb walls (and ceilings.) Godot 4 makes it really easy to attach to platforms and move with them, through moving the characterbody2d with move_and_slide() and using set_up_direction() to let them attach to the side or bottom instead. Climbing up or down a not-moving ledge is also pretty easy, but since I’m not married to the way I currently do it, it isn’t relevant to my question.

The platforms are AnimatableBody2D’s ran along a Path2d with the help an AnimationPlayer, PathFollow2D and RemoteTransform.

The problems start when, on a moving platform, the player wants to climb up or down a ledge, as when you set_up_direction(), the player detaches and is therefore no longer moved by the platform.

The other issue is that, when you want to for example climb down a ledge when standing atop a horizontally moving platform, I don’t know how to get the proper positions to calculate the movement, as both the platform and character move during physics_process(). When trying to go down a forward moving platform, the character smashes its face into the floor until the platform stops or turns around.

Do you have any suggestions of what options I could look into? Thanks in advance!