# 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:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mr.Oofus](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mr.Oofus](https://forum.makecode.com/u/Mr.Oofus)
#### Post date: [September 12, 2025, 6:08pm UTC](https://forum.makecode.com/t/lidar-game/39194/1 "2025-09-12T18:08:12Z")

</div>

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.

---

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

---

<div class="post-metadata">

### Author: ![Mr.Oofus](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mr.Oofus](https://forum.makecode.com/u/Mr.Oofus)
#### Post date: [September 16, 2025, 11:28pm UTC](https://forum.makecode.com/t/lidar-game/39194/3 "2025-09-16T23:28:25Z")

</div>

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