I am trying to implement 2D ledge grabbing in Godot, but don't know an elegant way to go about detecting ledges.
When I've done it in the past, in Python, my Player
had a bounding box with topleft
, topright
, bottomleft
, and bottomright
attributes, as did my Walls
.
When a scene was loaded, I would iterate through the corners of my walls to check which ones were "grabbable" (the method involved raycasting), and I would add them to a ledge list. If my player's top corners ever got near these points, I would change my player's state to grab.
In Godot, my player is a KinematicBody2D
, and although I have a bounding box attribute that is a Rect2
, Godot's Rect2
doesn't have corner attributes. Further, my walls are each a StaticBody2D
and also lack these attributes.
So, my question is: What is an elegant way to go about ledge detection in Godot?