0 votes

Hi everyone
I am making a 2d platformer game in the godot engine. Recently I have implemented some "invisible tricks" that make the game feel better like coyotetime, jump buffering etc. But I
came across another topic called ledge catching. This is when you are a few pixel away from the ledge of a platform but you are still able to get on top of it.
Can someone suggest an idea on how to this?

Godot version 3.4.4 stable
in Engine by (60 points)

1 Answer

0 votes
Best answer

A friend once suggested that I markup ledges to decide which ones should be grabbable, such as putting an Area2D on each ledge and responding when the player enters it. But that seemed like way too much work. I ended up dynamically detecting ledges with raycast sweeps. This is where you move a raycast in increments to determine where a collision starts or stops.

I put my raycast origin at my player's chest facing towards the travel direction. When the player is in the air I check that raycast to see if the player is within range of a wall. If so I start the sweep, moving the raycast up 4 pixels at a time still facing the travel direction. The first iteration that gets no collision tells me that I have a ledge within those last 4 pixels.

Once I find a ledge I do a finer 1 pixel sweep to get the exact ledge position. I then transition to a "ledge" state where my player grabs the ledge and can then pull themselves up.

by (272 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.