Fixed crash due to 'GameLogic::keyboard_events' was not initialized.
Refactored two functions in 'raycast.cpp' to avoid duplicated code.