Wolfenstein 3D-like raycasting

Debugging

Hi all,
For a while now, I've been trying to get to grips with 2d raycasting to achieve a wolfenstein 3D-like wall effect.

I can get get a basic raycaster to work but I come up against an issue where my walls are the same height when looking from a distance, but as you get closer, the walls curve inwards.

I've read this post, where the person answering talks about casting rays from "eye-space" to end up with a straight wall: https://computergraphics.stackexchange.com/questions/13821/raycasting-wall-slice-height-issue I've read this over and over, did countless drawings on paper to try and understand why this method gives straight walls at all times, but using `cos(rayAngle) * rayLength` gives a nearly accurate height yet still wrong. It's just not sinking in for me.

I think I'm thinking about the problem incorrectly maybe, not sure. The only reason I can come up with why the sine of any ray can only give a "nearly correct" wall height is due to the small variations of the value of sine based on the magnitude of the ray as it's being cast from the player in a top down 2D world.

I've read Lodev's article on the matter too, as well as many others. I think it comes down to a more fundamental gap in my knowledge somewhere but I don't where that gap is necessarily or what it is that I am visualising wrongly.

I'd be very grateful for any pointers & help.
Thanks for reading!

Posted May 4, 2024, 8:00 PM UTC

17
Loading comments…