how to make a characterbody2D stick to a surface and slide around corners?

Godot Version

4.6.2

Question

All I want to do is have a characterbody2D object in sidescrolling 2D that goes left and right. When the object comes into contact with any corner, it should just stick to the surface and keep traveling, like a slug crawling a wall or ceiling. I don’t need any kind of gravity or jump or anything else.

This seems like it should be REALLY simple but I can’t figure out for the life of me how to make it work. None of the slope settings in characterbody2D make any difference at all, and the few solutions I can find online all involve raycasting downwards but that only catches outward angled cliff-like corners. It doesn’t account for interior corners and ceilings.

Am I just approaching this wrong? There has to be an easy way to do this that I’m just not getting.

It seems like it should be easy because Godot is doing a lot of physics heavy lifting for you. Did you change this setting on your Character2D to Floating?

That’ll probably get you closer. As long as they can’t move up and down, you’re halfway there. They just see if the player is colliding with a surface and if so, change their movement direction. Unfortunately, when you get to a outward corner, you’re gonna have to use a RayCast2D to see that the wall ended and you need to turn again.