Lightning-fast raycasting!

  • 49 favourites

Attached Files

The following files have been attached to this tutorial:



Download now 177.7 KB


7,088 visits, 11,249 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Raycasting is the process of drawing a line from some point to measure the distance to the nearest solid. It has a huge number of uses, with beams and lasers being perhaps the most common. However raycasting is also used to measure angle relative to a solid, testing which solid is the closest, etc.

Here is my optimized raycasting function. It's fully commented and has two major optimizations - a system to pick only the relevant solids before raycasting, and a halving increment system to decrease the required iterations.

Feel free to use this in your projects! Credit is appreciated. Let me know if you have any questions or suggestions! I'm always looking for improvements.

[Updated 20/10/2014. Fixed bug where max range was higher than the max range parameter, and implemented Magistross' method for stopping the loop to slightly improve performance.]

The capx file is attached. (Over there, up and to the left)



Download now 177.7 KB

  • Order by
Want to leave a comment? Login or Register an account!