# Ray Casting

**URL:** <https://forum.makecode.com/t/ray-casting/30846>\
**Category:** Help\
**Tags:** game\
**Created:** [September 25, 2024, 9:35pm UTC](https://forum.makecode.com/t/ray-casting/30846 "2024-09-25T21:35:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregoa2](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@gregoa2](https://forum.makecode.com/u/gregoa2)\
**Post date:** [September 25, 2024, 9:35pm UTC](https://forum.makecode.com/t/ray-casting/30846/1 "2024-09-25T21:35:54Z")

</div>

> **[Pacman Game](https://arcade.makecode.com/S21822-10743-77589-22054)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

My student is having trouble with ray casting. He made some changes and his code started glitching and giving him the error message: Program Error: sim error: failed cast on null. We can’t figure out what happened. Any help would be much appreciated.  
Thanks,  
Ms. G.

---

<div class="post-metadata">

**Author:** ![sarah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarah/32/33518_2.png) [@sarah](https://forum.makecode.com/u/sarah)\
**Post date:** [September 25, 2024, 9:40pm UTC](https://forum.makecode.com/t/ray-casting/30846/2 "2024-09-25T21:40:45Z")

</div>

Hi!

I’m not sure if there is anything else your student is looking for help with, but they are getting the “Failed cast on null error” because, in the forever loop, they are accessing the variable `Clyde` when `Clyde` does not get initialized until the user presses “B”. To avoid getting this error, your student can either initialize `Clyde` in the on start or can add another condition in their forever condition like so:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/c/3/c32094795d5d6c05f772ff6fb216f8c7cbcd8a55.png)

Here is a copy of the code working (with the suggested change above implemented) if you would like to check it out: [https://makecode.com/\_fP7TxL6qxLz3](https://makecode.com/_fP7TxL6qxLz3)

---

<div class="post-metadata">

**Author:** ![gregoa2](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@gregoa2](https://forum.makecode.com/u/gregoa2)\
**Post date:** [September 25, 2024, 9:43pm UTC](https://forum.makecode.com/t/ray-casting/30846/3 "2024-09-25T21:43:04Z")

</div>

Thank you so much! We will definitely try that and I will let you know.
