How to properly raycast?

So I’m trying to see if my character can detect the edge of a layer & / or edge with a raycast so I can stop the character from twitching when getting ready to fall off. how to do this?