# Raycasting floor texture distortion problem

I'm currently working on a raycaster in construct 2.

The FOV is 90 degrees with a screen resolution of 199 x 174. I used this tutorial when it comes to the floor raycasting.

The floors seem to render properly seam-wise, if that makes sense, but the textures themselves (for each square of the floor if you will) appears distorted in a circular motion. I think this happens when it comes to the part of displaying the correct part of the texture.

The tutorial towards the end says that it is to pick a pixel of the texture using

floor_point.x = player.x + cos(alpha) * d

floor_point.y = player.y - sin(alpha) * d


with alpha being the angle of the ray cast relative to the player (I believe, correct me if I'm wrong, I'm not 100% sure if alpha is actually the ray angle), and d being the distance of the floor point. I believe this is where I have a problem when it comes to determining the part of the texture to display.

How mine works is that the floor itself is a 32 x 32 tilemap with each tile being 1 pixel, having a range of 1024 tiles. I obtain the floor point X and floor point Y, they are modded to 32 since that is the texture width and multiplied to each other, so the tile it picks can be a range of 1024.

With the FOV being 90 and screen width being 199, the distance to projection plane is 199/tan(45) which equals to 122.856555133. The player height is set to 32.

The formula below is used to determine the pixel (tile for the tilemap) for each floor point.

  (player.x + cos(ray.angle) * ((playerheight * 122.856555133 / (floorpoint.y) / Cos(abs(ray.angle - player.Angle))))%32)
* (player.y - sin(ray.angle) * ((playerheight * 122.856555133 / (floorpoint.y) / Cos(abs(ray.angle - player.Angle))))%32)


Here's what the original texture is supposed to be displayed as

Here's what the floor looks like

and here's the same problem but the square size is bigger to make it more clear

Is modding the X and Y points to 32 what may be causing the problem? I'm not sure what math is incorrect here unless I did get the "alpha" variable from the tutorial confused with something else.

• Please note that there was some "errors" with parenthesis in your formula; I "removed" it but you might want to double check it. You should probably review it anyway to make it a bit more understandable to users (e.g. present it in a way that we do not need to scroll or something..). Aug 31, 2021 at 14:13