I'm currently trying to figure out a way of getting the distance from a bullet to a person at its closest point. Getting an equation of the bullet is relatively easily. I've converted it into two vectors, position[3] & direction[3].
I then have a client and I can get a position[3] vector of them as well, but I'm struggling to visualize a way of finding the closest distance between these two points quickly. My initial thought is using some maths:
But I'm wondering whether there's either an easier or quicker way of doing the equation. In case this is an AB problem, my use case is that I'm trying to find out the nearest person shot with every bullet fired. Unfortunately, my current system is to work out the closest distance between the shot and every single player on the server (upto 40), which might mean this isn't possible to do in an acceptable period of time since I'd also be doing it on every shot.
One error in my calculations I've worked out so far is that I don't take into account that there could be a wall in the way. I could trace ray it to find when the bullet does hit a wall, but mathematically this makes things significantly more complex since lines are infinite. One would have to find the point that is nearest to the client on the line, then work out whether that point is past the bullet strike point or before the person shot point, then place that point on the line and work out the distance again between the new point and the client. This seems to be growing exponentially more painful the more I think about it.
(This is in relation to the CS:GO gamemode)