Lightning-fast raycasting!

2

Attached Files

The following files have been attached to this tutorial:

.capx

optimized-raycaster.capx

Download now 177.7 KB

Stats

7,374 visits, 11,585 views

Tools

Translations

This tutorial hasn't been translated.

License

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.

Published on 11 Mar, 2014. Last updated 19 Feb, 2019

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.7 KB
  • 0 Comments

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