Up to date

This page is up to date for Godot `4.2`. If you still find outdated information, please open an issue.

# AABB¶

A 3D axis-aligned bounding box.

## Description¶

The AABB built-in Variant type represents an axis-aligned bounding box in a 3D space. It is defined by its position and size, which are Vector3. It is frequently used for fast overlap tests (see intersects). Although AABB itself is axis-aligned, it can be combined with Transform3D to represent a rotated or skewed bounding box.

It uses floating-point coordinates. The 2D counterpart to AABB is Rect2. There is no version of AABB that uses integer coordinates.

Note: Negative values for size are not supported. With negative size, most AABB methods do not work correctly. Use abs to get an equivalent AABB with a non-negative size.

Note: In a boolean context, a AABB evaluates to `false` if both position and size are zero (equal to Vector3.ZERO). Otherwise, it always evaluates to `true`.

Nota

There are notable differences when using this API with C#. See Diferencias de la API de C# con GDScript for more information.

## Properties¶

 Vector3 end `Vector3(0, 0, 0)` Vector3 position `Vector3(0, 0, 0)` Vector3 size `Vector3(0, 0, 0)`

## Constructors¶

 AABB AABB ( ) AABB AABB ( AABB from ) AABB AABB ( Vector3 position, Vector3 size )

## Methods¶

 AABB abs ( ) const bool encloses ( AABB with ) const AABB expand ( Vector3 to_point ) const Vector3 get_center ( ) const Vector3 get_endpoint ( int idx ) const Vector3 get_longest_axis ( ) const int get_longest_axis_index ( ) const float get_longest_axis_size ( ) const Vector3 get_shortest_axis ( ) const int get_shortest_axis_index ( ) const float get_shortest_axis_size ( ) const Vector3 get_support ( Vector3 dir ) const float get_volume ( ) const AABB grow ( float by ) const bool has_point ( Vector3 point ) const bool has_surface ( ) const bool has_volume ( ) const AABB intersection ( AABB with ) const bool intersects ( AABB with ) const bool intersects_plane ( Plane plane ) const Variant intersects_ray ( Vector3 from, Vector3 dir ) const Variant intersects_segment ( Vector3 from, Vector3 to ) const bool is_equal_approx ( AABB aabb ) const bool is_finite ( ) const AABB merge ( AABB with ) const

## Operators¶

 bool operator != ( AABB right ) AABB operator * ( Transform3D right ) bool operator == ( AABB right )

## Property Descriptions¶

Vector3 end = `Vector3(0, 0, 0)`

The ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to `position + size`. Setting this point affects the size.

Vector3 position = `Vector3(0, 0, 0)`

The origin point. This is usually the corner on the bottom-left and back of the bounding box.

Vector3 size = `Vector3(0, 0, 0)`

The bounding box's width, height, and depth starting from position. Setting this value also affects the end point.

Note: It's recommended setting the width, height, and depth to non-negative values. This is because most methods in Godot assume that the position is the bottom-left-back corner, and the end is the top-right-forward corner. To get an equivalent bounding box with non-negative size, use abs.

## Constructor Descriptions¶

AABB AABB ( )

Constructs an AABB with its position and size set to Vector3.ZERO.

AABB AABB ( AABB from )

Constructs an AABB as a copy of the given AABB.

AABB AABB ( Vector3 position, Vector3 size )

Constructs an AABB by `position` and `size`.