Check to see which radius' a line passes through

So, I have an array of points in my game scattered on the map. Every single point has a radius of 4 meters, with sphere effects to show where they are.

I have a point that goes directly out from my facing position exactly 30 meters. If you drew an invisible line between my eye position and the point 30 meters out, I want to have an array that shows which spheres the line between the two points passes through. What kind of equation or rule would I need to acquire that array? I’m not the best with math, so any help would be appreciated! Thanks!

There are two (kind of similar) ways to do so:

NF264
This demonstration code I once made works as follows: You create a vector a from the players eyes to the center of the sphere and a second vector b wich is orthogonal to the players facing direction and has the length of the radius of the sphere (e.g. with normalize(cross product(facing direction(event player), world vector of(left, event player))) * 4). Now you need another vector c wich is the vector from the eye position to (center of the sphere + vector b). Then you calculate the angle x between vector a and vector c. If the angle y between the facing direction and vector a is <= angle x, the player is currently aiming at the sphere.

This demonstration works similar to the first one, but in this case we don’t calculate the angles, but create a vector v from the center of the sphere to the facing direction in a way that v is orthogonal to the facing direction. If the length of v is <= the radius of the sphere, the player is aiming at the sphere.

1 Like