maybe this post explain it better How to make a raycast pointing in the mouse direction with a certain lengh