Lidar Game

I want to make a Lidar game, but I can’t figure out how the raycast makes the vectors, and I’ve been trying to find a way to take the collision data from the rays. I’ve looked through the extension code, but I don’t understand some of the variables and math.

2 Likes

The code the raycasting extension uses to find the distance to a surface is located around line 515 in the render_raycasting.ts file. I’ve actually seen and used this method of raycasting before! It’s a quite clever ray casting algorithm that is optimized specifically for tiled maps, where everything on the map is a square on a grid. This YouTube video by javidx9 explains it quite well: https://youtu.be/NbSee-XM7WA?si=LQ7WKsI8LMP-5Zps

The specific implementation uses some fancy bit shifting to make it faster, but it’s still the same math.

Following through the code, is seems that the variables mapX and mapY end up being used to check the tile on the map, and the actual distance ends up in a perpWallDist variable, which then gets put into that this.dist[ ] array to be used later for sorting sprite textures so that they appear behind and in front of all the correct walls.

1 Like

Thank you so much! I was really stumped, and this helped so much!

1 Like