So I want to do a line trace against an object and get multiple hits on that object. I am doing this with a complex trace. How I would want this to work would be something like this:
----x[ ]----x[ ]----->
Where the dashes are the line trace, the x’s are hits and the brackets represent part of the mesh. My thought on how to accomplish this would be to do one line trace, then at the hit location of that line trace do another one. However, this leads to initial overlap issues, which I’m not entirely sure how to ignore.
Multi line trace is out of the question, since it only works once for each object / component
After the first overlap, you’ll need to set the trace start location forward by some step distance, along the direction of the trace. then trace back to see the unoverlap location if it exists (if you need this). Then trace further forward until the next overlap if it exists, and do this in a loop.
That’s a tough one, but it got me thinking. And what I came up with is basically what @BenVlodgi suggested. Looks like that’s the most obvious path to take, if I dare call it obvious.
Basically what is does is it detects a hit, then moves the point along the same vector until that point no more overlaps the actor, and then sends another trace at the same angle. It can be done multiple times depending on how many layers you want to penetrate. Here’s the result:
The last index in the ForLoop determines the thickness of the wall you want to penetrate. 1024 is too much, of course, that’s just for testing purposes.
I don’t know how expensive that would be in terms of performance, if you have a lot of bullets flying or something like that, but it works.
Additionally, you can send a trace in the opposite direction from the last Impact Location and apply a decal to the inner face of the wall, if we’re really talking about bullets penetrating a thin wall.
I think what @BenVlodgi is going to be more performant than this, since it would be at most 2 line traces for each hit rather than a potential n amount of still overlapping checks.
Agreed, but if you set a certain fixed distance to the trace that will check the back wall, it may happen that it will actually be behind the second wall if there are two of them quite close to one anohter. But if you know that that won’t be the case in your project, then yes, that would definitely win in terms of performance.
You’re right, but as far as I can tell, you’re adding by a fixed increment in your solution, so I think its fair to say that its possible that your solution would give the incorrect answer as well if the walls are closer than a cm apart, which I believe could be the case in my project.