Raised This Month: $32 Target: $400
 8% 

Find distance between person and bullet trail


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
popey456963
Member
Join Date: Mar 2016
Old 09-25-2017 , 23:34   Find distance between person and bullet trail
Reply With Quote #1

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)

Last edited by popey456963; 09-26-2017 at 00:11.
popey456963 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 09-26-2017 , 03:28   Re: Find distance between person and bullet trail
Reply With Quote #2

I guess your starting point for the math was the distance between two lines. But you can, indeed, do a little better. Here's a SO answer with samples. Only third snippet is for 3D, but it's not really any different than the other 2D snippets.

You can probably get the impact point of the bullet somehow, but I don't know how. There's a bullet_impact event in CS:GO, but I don't know if it's fired or if it's accurate. If the event doesn't work out, doing some poking around/reverse engineering in the server would definitely yield results if you have the ability and motivation to do it.

Checking for people behind walls from the bullet path's point of view probably can't be done without a trace for each player. You could cull the player list by doing a single hull trace first to select a potential set of targets, since anyone too far away could be discarded.
Fyren is offline
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 09-27-2017 , 01:47   Re: Find distance between person and bullet trail
Reply With Quote #3

Maybe this will help you by looking at the code of it :

https://forums.alliedmods.net/showth...26328?p=526328
__________________
Waiting for HL3,Day of Defeat3 ,but will it ever come? So I'm gonna play COD WW2.>>>>SM_SKINCHOOSER<<<<
>>You need Models for DODS/CSS/CSGO , than click here!!!<<
andi67 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode