I have same problem in old patch too! Here is solution for you xD
Well, i've integrated your solution, yes its working, in case with mortar team, but i still have troubles with differen units.
(i adopted it in Jass polar projection function, for the test i disabled projection part, simply lefting moving part)
How pair moratr and footman works with this function
I thinkg we should solve exact case. I have troubles with Night Elf balista base.
While writting this post i've decided to check what the difference between the cases, and the first which came to mind was the collision side, especially after part of the code in your solution checking that collision. After that i've noticed that higer number of this check is 32, which is exact collision sive of the mortar team, i quickly changed collision sive of the ballista to the collision sive of 32. Result i had.
Its hard to see, but the footman right in the center of the ballista, you can notice a little part of the shield, poping under center blade of a glaive to the left.
Pwnica was right. Coliision in this case matters.
And it solved the problem i had with tha main unit for which i did this trigger.
So developing this idea, if i want to use old collision 48.00 i need change this function, replacing 32 with 48 and 16 with 24?
Well, i actually tried it(function aimed for unit with 48.00 collision size, which i discribed above), and result wasnt so smooth. But that atleast something.
How better adjust this function for such cases?
And after that, i've noticed that after setting collision size on 32, other attached units, which i attach without using function with implemented collision check, positioned correctly, i've decided to test ballista unit with locust based unit with simple SetUnitX and Y without collision checks, and found out that for that case, i dont need this function at all, because changing collision on 32 fixed that alone. But still it we can say the system is working on case when in place of locust turret was fotman and in case with mortar and footman. So the main question, how to handle collision size larger than 32?