I'm new to the forums but I'll try to help:
You could use the AABB class to find to the coordinates of the top plane of the object (as shown below in the getupwardsplane function).
This is where I think it gets tricky, trying to figure out when you should let the object in question fall or stick to the edge of the wall. One way you could do it is by having a collision box and detecting collision, and figuring out the point of collision, for example using CharacterBody3D's
get_slide_position(), and getting the
.position attribute from that.
Sample Code (not tested):
mesh = get_node(mesh_path).get_aabb() # get the bounding box of the mesh
corner_1_pos = mesh.position # these are Vector3s
corner_2_pos = mesh.end
corner_1_pos.y = corner_2_pos.y # getting the top 2d plane
collision_pos = self.get_slide_collision().position
if is_inside_of_plane(): # this would be several if statements if the position is inside/on top of the coords of the two corner_pos
velocity.y == 0 # sample of cancelling velocity on the y to sit on the edge