Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Diet Estus |
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?
The way I detect ledges is by checking two points using interact_point().
I then check two points to determine if the player is grabbing a ledge or not. One in the top corner of the direction the player is facing, and another from the middle to the wall.
If the top corner is not colliding with the tilemap and the middle point is then I consider it a ledge. If both points are touching the tilemap, then it is not a ledge, but a wall.
madcapacity | 2018-03-23 02:13