RayCast Pathfinding?

I wanna make raycast pathfinding that make a npc/player walking through all edges.

So, i get this algorithm:
1.We shoot ray from origin to our position.
2.If we hit something, we make a point, get surface, and go to the edge that much closer to position
3.Start new ray
4.Repeat

My problem is: How i can get the edges and how i can get how close it to position? I think it’s CFrame used here, but i don’t know anything from CFrame.