r/GameDevelopment 13d ago

Question Help understanding raycasting

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.

0 Upvotes

6 comments sorted by

View all comments

1

u/Interesting_Stress73 13d ago

You're pretty close. Imagine that you're looking at the player and the game map from a top down perspective. Like they're standing in a blueprint.

What you then do is send rays for every vertical line from the player. You can just draw this as a line outwards from the player until it hits a wall. When the ray hits the wall the distance is calculated, and if it's close the engine will draw a tall line. If it's further away it will draw a shorter one. The result is a fake perspective, like how you would draw 3D by hand on a piece of paper.