Restricting a character's movement at a ledge?

Is there anything that can be done to fix problem?