Refactor performing raycast into a function.