PhysicsAABB
Represents a 2D axis-aligned bounding box.
Read time 2 minutesLast updated 12 days ago
Definition
- Type: Struct
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
- Implements: IEquatable<PhysicsAABB>
public struct PhysicsAABB : IEquatable<PhysicsAABB>
Remarks
Use a with PhysicsWorld.TestOverlapAABB to check if a bounding box overlaps another object in the world, or with PhysicsWorld.DrawAABB to draw it for debugging.
PhysicsAABBAdditional Resources: PhysicsWorld.TestOverlapAABB
Examples
// Check whether a bounding box overlaps anything in the world.using UnityEngine;using Unity.U2D.Physics;public class TestOverlapAABBExample : MonoBehaviour{ void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; PhysicsAABB aabb = new PhysicsAABB(new Vector2(-1f, -1f), new Vector2(1f, 1f)); bool overlaps = world.TestOverlapAABB(aabb, new PhysicsQuery.QueryFilter()); }}
Constructors
Constructor | Description |
|---|---|
| PhysicsAABB(UnityEngine.Vector2) | Create an axis-aligned bounding-box that encapsulates the specified point. |
| PhysicsAABB(UnityEngine.Vector2,UnityEngine.Vector2) | Create an axis-aligned bounding-box with the specified bounds. |
Properties
Property | Description |
|---|---|
| center | Get the center of the AABB. |
| extents | Get the extents (half size) of the AABB. |
| isValid | Check if the AABB is valid. To be valid, _upperBound should be equal to or above _lowerBound. |
| lowerBound | The lower-left bounding vertex. This should be equal to or lower than _upperBound. |
| normalized | Get a new normalized copy of the AABB ensuring that _lowerBound is lower than or equal to _upperBound. |
| perimeter | Get the surface area (perimeter length) of the AABB. |
| upperBound | The upper-right bounding vertex. This should be equal to or above _lowerBound. |
Methods
Method | Description |
|---|---|
| CastRay | Perform a raycast against this AABB. Nothing will be detected if the ray starts inside the AABB. To check if the ray starts inside the AABB use PhysicsAABB.OverlapPoint. |
| Contains | Checks if the AABB contains (completely encapsulates) the specified AABB. |
| Normalize | Normalize the AABB ensuring that _lowerBound is lower than or equal to _upperBound. |
| Overlap | Check if the specified AABB overlaps this AABB. |
| OverlapPoint | Check if the specified point overlaps this AABB. |
| Translate | Create an AABB as a translated version of the current AABB. |
| Union | Create a union of the specified AABB and this AABB where resulting AABB completely encapsulates both AABB. |