BBox GetLocalBounds()

robot_2Generated
code_blocksInput

Description

The GetLocalBounds method of the GameObject class returns the local bounding box of the game object. This bounding box is calculated based on the object's local space, which means it is relative to the object's own transform, not taking into account any parent transforms or world space positioning.

Note: This method is slow and somewhat inaccurate, so it is not recommended to call it every frame.

Usage

Use the GetLocalBounds method when you need to determine the local bounding box of a GameObject for purposes such as collision detection, visibility checks, or spatial queries within the object's local space. Be cautious of its performance implications and avoid calling it frequently, especially in performance-critical sections of your code.

Example

// Example of using GetLocalBounds
GameObject myObject = new GameObject();
BBox localBounds = myObject.GetLocalBounds();

// Use the localBounds for further processing
Vector3 size = localBounds.Size;
Vector3 center = localBounds.Center;

// Output the size and center of the local bounds
// (Avoid using Console.WriteLine in Sandbox environment)
DebugOverlay.Text(size.ToString(), myObject.WorldPosition);
DebugOverlay.Text(center.ToString(), myObject.WorldPosition + Vector3.Up * 10);