Consider turning the ray trace into a function,
you can put the results of each trace into an array and do a for each loop where you then find the result your looking for i think i saw your other post a moment ago, finding the longest distance this way would be the easiest
a lil something like this