Garry's Mod Wiki

Revision Difference

Entity:WorldSpaceAABB#568552

<function name="WorldSpaceAABB" parent="Entity" type="classfunc"> <description>Returns two vectors representing the minimum and maximum extent of the entity's axis-aligned bounding box (which is calculated from entity's collision bounds.</description> <realm>Shared</realm> <rets> <ret name="" type="Vector">The minimum vector for the entity's bounding box in world space.</ret> <ret name="" type="Vector">The maximum vector for the entity's bounding box in world space.</ret> </rets> </function> <example> <description>Prints Entity(1)'s maximum bounding box vector.</description> <code> local min, max = Entity(1):WorldSpaceAABB() print( max ) </code> <output>-496.828125 11730.426758 5189.393066</output> </example> <example> <description>With `developer` set to `1`, draws the AABB of given entity using <page>debugoverlay</page>.</description> <code> local lastEntLatch = NULL hook.Add( "PostDrawTranslucentRenderables", "HUDPaint_DrawWSAABB", function() hook.Add( "PostDrawTranslucentRenderables", "DrawAABBofLastLookedAtEntity", function() local entAtCrosshair = LocalPlayer():GetEyeTrace().Entity if ( IsValid( entAtCrosshair ) ) then lastEntLatch = entAtCrosshair end ⤶ ⤶ if ( !IsValid( lastEntLatch ) ) then return end⤶ ⤶ render.SetColorMaterial() -- white material for easy coloring⤶ ⤶ if ( !IsValid( lastEntLatch ) ) then return end⤶ ⤶ render.SetColorMaterial() -- colorable material⤶ local mi2, ma2 = lastEntLatch:WorldSpaceAABB() render.DrawBox( Vector( 0, 0, 0 ), Angle( 0, 0, 0 ), mi2, ma2, Color( 255, 255, 255, 50 ) ) -- draws the box render.DrawBox( Vector( 0, 0, 0 ), Angle( 0, 0, 0 ), mi2, ma2, Color( 255, 255, 255, 50 ) ) render.DrawWireframeBox( Vector( 0, 0, 0 ), Angle( 0, 0, 0 ), mi2, ma2, Color( 255, 255, 255 ), true ) end ) </code> <output><upload src="70c/8da74add0f1dc5b.png" size="566262" name="image.png" /></output> </example>