How DO vehicles do that, code wise, I wonder tho....
Looking at the code for the Juggernaut (GROUNDVEHICLES_A5_JUGGERNAUT_HEAVY_ASSAULT_VEHICLE.XML) it seems like the garrison code uses the following:
CanContainGarrison in the <Property_Flags> tag;
GARRISON_VEHICLE in the <LandBehavior> tag;
and then a group of tags that look like this:
<Garrison_Category>Infantry, Droid, Wheeler, Tracker, Walker, Landspeeder, Airspeeder</Garrison_Category>
<Num_Garrison_Slots>10</Num_Garrison_Slots>
<Garrison_Bone_Names>Garrison_00, Garrison_01</Garrison_Bone_Names>
<Garrison_Exit_Dist>0</Garrison_Exit_Dist>
<Garrison_Enter_Dist>0</Garrison_Enter_Dist>
<Garrison_Radius>50</Garrison_Radius>
<Num_Garrison_Guns>0</Num_Garrison_Guns>
Changing the values in <Garrison_Enter_Dist> and/or <Garrison_Radius> may change how far a unit needs to be to board. <Garrison_Exit_Dist> is probably how far the unit moves when it leaves the vehicle. Changing <Num_Garrison_Guns> should allow the units inside to fire on enemies outside, similar to the capturable bunkers (the bunker has a value of 8 for that tag).