r/howdidtheycodeit • u/Prudent_Surprise7356 • Jul 24 '26
How does raycasting work?
Hi all. I'm trying to find out how raycasting works — like in Wolfenstein 3D.
And as someone who knows absolutely nothing about programming, I (think I) understand it is thusly:
Raycasting is a programming trick that grants 2D maps a fake 3D appearance through the use of invisible rays that project outward from the player and detect collision.
Corrections to my nonsense would be appreciated!
I am currently writing an article, and I would like a layman's understanding before I commit to anything in there.
30
Upvotes
View all comments
Show parent comment
18
u/empty_other Jul 24 '26
Nice answer. Wolfenstein didn't actually draw a floortile. Just drew a light gray square on the bottom 50% of the screen before drawing the walls. Doesn't really draw a cube either, just a textured 1px vertical line that is shorter or taller depending on distance and some fisheye maths, that when put together looks like a cube.
Here's a tutorial for making this on your own: https://youtu.be/vYgIKn7iDH8
Also stuff done in Doom and Duke3D to make "overlapping" rooms with the same technique is awesome. I had a YT showing how it rendered it, but can't find it.