Professional Documents
Culture Documents
2d Raycasting
Main resources
The blue line is the camera plane and it should be always perpendicular on the direction vector of the player. The camera
plane represents the surface of the computer screen.
Since the camera plane is 1D and the computer screen is 2D, we need an extra dimension,
this extra dimension is obtained by counting on the ray length (which is the distance from the
player to the wall following the direction of the ray).
Notice: you have to spite the if into two distinct if . If for x and if
for y
To prevent the rounded
effect, we will use
perpWallDist instead of
Euclidean
The final step is to calculate the wall_x
Wall_x: where the ray hit the wall
https://www.geogebra.org/classic/e8fgsehy
https://www.geogebra.org/calculator/w5pd57rm
CameraX represent x.
Dist represent y.
You can play with value of cameraX and Dist in the
above link to get an idea.
Sprites
Sprites
cameraX
Final result