# Lidar Game

**URL:** <https://forum.makecode.com/t/lidar-game/39194>\
**Category:** Help\
**Tags:** make, game\
**Created:** [September 12, 2025, 6:08pm UTC](https://forum.makecode.com/t/lidar-game/39194 "2025-09-12T18:08:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [September 14, 2025, 7:35pm UTC](https://forum.makecode.com/t/lidar-game/39194/2 "2025-09-14T19:35:28Z")

</div>

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](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.

---

_[View the full topic](https://forum.makecode.com/t/lidar-game/39194)._
