Ray casting is a technique usually used in 3D worlds (often for rendering). Ray casting is exactly what it implies a ray is cast from a start point until it hits something (or a max length, so the computer doesn’t die). Ray casting in 2D is great for collision detections, especially fast-moving objects (bullets).

In this post, we will learn the basics of ray casting in 2D, then we will apply it to bullets in a simple environment.

A ray is just a line. It has a start point and an end point. In order to use this method effectively, we need More >