Discord
Community
DARK THEME

# How do I make a raycaster?

I'm working on a wolfenstein3D clone but have no idea how to make a raycaster.

I can't quite explain it, but I can point you to some tutorials:

There's one issue with most tutorials that I couldn't manage to fix (I think the code from the tutorial I've followed doesn't make it possible to fix). The issue is that walls look rounded at the top and bottom, and it's only really noticeable with high FOVs. Most tutorials use low FOVs of around 60.

I've seen some implementations in MicroStudio that have perfectly straight walls, but I couldn't figure out how they did it.

There's also this one: https://medium.com/@btco_code/writing-a-retro-3d-fps-engine-from-scratch-b2a9723e6b06

Which is a tutorial for the TIC-80, but he also teaches some good stuff, and the game he made is actually quite good, in technical terms (including straight walls).

I'm not really good at rewriting code

Then you might want to void the first tutorial I listed, because that one is pretty much like a code-along kind of thing, with not much explanation.

All the others have actual explanations of how things are done.

The problem is due to you are calculating the actual wall distance (the closer the ray goes to the edge of the camera plane, the longer they get). And the longer a ray is, the smaller it will be projected onto the camera plane, this is the typical fish eye effect. However for a raycaster, you have to calculate the perpetual wall distance from the draw plane (so each ray has the same length). Try not to just copy (or type code) but to understand what you are coding. Try to understand the problem you are trying to solve, otherwise when you do not understand the problem, you wont be able to find a solution.

This is the best raycaster tutorial on the internet imho: https://lodev.org/cgtutor/raycasting.html everything you need to know is explained there, also the "fish-eye-problem":

... We don't use the Euclidean distance to the point representing player, but instead the distance to the camera plane (or, the distance of the point projected on the camera direction to the player), to avoid the fisheye effect. The fisheye effect is an effect you see if you use the real distance, where all the walls become rounded, and can make you sick if you rotate...

- from https://lodev.org/cgtutor/raycasting