How do I make raycast not pass through walls?

Thank you very much. This is a bit complex for a beginner like myself, but I’ll use it as an opportunity to learn.