Dynamic height vaulting?

Godot Version

v4.2.1.stable.official

Question

Hello all. So right now I have a system set up where the character can hang from a ledge. There is then an Area2D detecting whether there is space to vault above, if so then upon pressing button a vault is activated and your character goes up and over the ledge using a tween with hard coded values for how far the character will travel. Now the complexity comes in because I’m going to add features where you can vault over ledges of various heights and there are some edge cases with crouching and prone position etc. so I need a way to be able to make a more precise vault to accommodate various heights but I’m not sure how to go about it. Maybe I can snap the body to the edge so it follows it closer but I’m not sure lol, any suggestions would be appreciated, thank you.

Here is one approach you could try to determine the ledge height:

  1. Shoot a horizontal ray towards the direction of the wall (hit point: hPos)
    to detect the x-position of the wall
  2. Shoot a vertical ray downwards from the hPos + epsilon to detect the
    y-position of the ledge
  • epsilon: a small value that is used to avoid an edge-case where the ray narrowly avoids the target due to a floating-point error.

image

After this info is obtained, it’s just a matter of performing an animation at a specific position relative to the obtained point.