distance to the crossing of 2 lines (Line Trace)

hi,
sorry for late reply but here it comes ^^
(edited a few times, images are below to download, you cant see much on some)

a quick overview before we start…





one hits something the other does not

both hit the same target but notice the intersection is inside the cone

an here you see you can look even after hit if the line trace has an intersection

ok lets do it :smiley:
lets start with the line tracers…

this is your actor who fires a line trace. note the actor has an variable called ID, which is a simple INT. ATM there are only 2 IDs available, 0 and 1 but you can expand as you like.
this has the purpose to save the values for the marker, you could just fire the LineIntersect function when you know your 2 lines.

if you do not want intersections happen if something was hit, change the line trace from trace end to impact point.

here in my Gamestate (you could put it somewhere else) i made this function to store the lines so i can get my marker to show up. this is not required. it has the LineIntersections variable which is an Vector Array with 4 entries (line a start, line a end, line b start, line b end) and LineIntersectionX which is simply a Actor for the marker like in the pictures.

ok lets start with the main actor :stuck_out_tongue:

this is a function library, so we can access this function globally.
the local variables are needed for calculation, i mean you can let them out but then you will end up in spagetti nightmares :smiley:

ok here is the function, i made it out of several pictures, it wont fit on one screen to read…

please excuse the guerilla style snipped here ^^

this is the main function for intersection 2 lines. i made the same in unity but here i used an other algorithm, it is based on an algorithm in Andre LeMothe’s “Tricks of the Windows Game Programming Gurus”.

hope this points you in the right direction, z i the average point ATM but this can be tweaked :slight_smile:


as i said before you can only take the line intersection function, subtract your actors location where you like to know the distance from the intersection point :slight_smile:
in this picture i just took the start of line A.

i hope this helps you out, would be better to make a c++ function but by the time i have not setup everything to do so…

cheers :vulcan_salute:

here are the images in rar
images.rar (3.5 MB)
i see there is a problem with larger images, they get scaled and you cant see anything :frowning:

2 Likes