Fixed raycast distance calculation