Raycasting is a way for a computer game to work out what lies in a particular direction. Imagine pointing a laser from your character’s eyes or weapon, the game then follows that invisible straight line, called a ray, and checks which object it hits first and how far away it is. This helps the game decide whether a shot hits a target, an enemy can see you, or something blocks your path. Some games also cast many rays across your view to draw walls at the right height, making a flat map appear three-dimensional.
Throughout the following notes I will be using the Simple DirectMedia Layer 3 Library otherwise known as SDL 3 in the C Programming Language. I may use other libraries but only when necessary, for example for mathematics to make the code simpler to read and understand.