Creating Portal on edge of wall

Hi all, so I’m firing a line trace from my gun to a flat wall to create a portal but if that line trace hits at the edge of the wall, the portal spawns half off the wall. Is there any way I can fix this where if the line trace was near the edge of the wall it would spawn the portal on the wall fully and not floating half off the wall.
Any help is much appreciated, thank you.

You could shoot an array of parallel traces and depending on which trace hits what, displace the portal.

I did also think of this, I just feel like there is some better way to do it, I’ll try it anyways since I haven’t thought of any other way, thanks!