I'm so close to getting it working, I'm pretty sure there is an issue with detecting if the ray has hit a wall, but I can't figure it out. Everything works fine in a Desmos graph, but here it doesn't.