Garry's Mod Wiki

Entity:WorldSpaceAABB

  Vector, Vector Entity:WorldSpaceAABB()

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.

Returns

1 Vector
The minimum vector for the entity's bounding box in world space.
2 Vector
The maximum vector for the entity's bounding box in world space.

Example

Prints Entity(1)'s maximum bounding box vector.

local min, max = Entity(1):WorldSpaceAABB() print( max )
Output: -496.828125 11730.426758 5189.393066

Example

With developer set to 1, draws the AABB of given entity using debugoverlay.

local lastEntLatch = NULL 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() -- colorable material local mi2, ma2 = lastEntLatch:WorldSpaceAABB() 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 )
Output:
image.png