Lightning-fast raycasting!

Attached Files

The following files have been attached to this tutorial:

.capx

optimized-raycaster.capx

Download now 177.7 KB

Stats

4,163 visits, 6,725 views

Translations

This tutorial hasn't been translated.

Tools

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)

.CAPX

optimized-raycaster.capx

Download now 177 KB
  • 0 Comments

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