How do I make a raycaster?
I'm working on a wolfenstein3D clone but have no idea how to 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:
I followed this tutorial while making mine: https://www.youtube.com/watch?v=ECqUrT7IdqQ
This tutorial also teaches floor/ceiling casting, looking up/down, and more: https://www.permadi.com/tutorial/raycast/rayc8.html
I also found this video series interesting: https://www.youtube.com/watch?v=ssm2jMd40p4&list=PLLfIBXQeu3abu3JLlTLLSn9ctV1t2YnkW
And I got this one from Matth's raycaster in MicroStudio (scroll down a bit and find "Raycasting"): https://lodev.org/cgtutor/index.html
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've had trouble wrapping my head around it, though.
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...