How to make downward raycast only return a hit for the top an object?

I’m trying to implement a wall ledge grab system with raycasts. I’m having trouble with the raycast returning a hit just because it’s inside the wall when the player model pushes up against a wall. I only want it to return a hit when it has made contact with the top of a wall. How do I do that?

@meritakol

An idea (can’t remember how I’ve done this exactly, but it was something like this).

You could raycast so that start position is in front of your character, on height of arms extended up.

When you do a raycast, check if your hit y-position is different and smaller than start position. This way you know that your raycast started in open space and then hit a wall below.