Show:
Module: p5.play
Parent Module: p5.play

An Oriented Bounding Box (OBB) collision shape, used to detect overlap and compute minimum displacement vectors with other collision shapes.

Constructor

p5.OrientedBoundingBoxCollider
(
  • center
  • width
  • height
  • rotation
)

Defined in lib/p5.play.js:5851

Parameters:

  • center p5.Vector

    of the rectangle in world-space

  • width Number

    of the rectangle (when not rotated)

  • height Number

    of the rectangle (when not rotated)

  • rotation Number

    about center, in radians

Methods

_getCandidateAxes () Array.
protected

Inherited from p5.CollisionShape but overwritten in lib/p5.play.js:6073

Compute candidate separating axes relative to another object.

Returns:

Array.
_getMinRadius
(
  • axis
)
Number
protected

Inherited from p5.CollisionShape but overwritten in lib/p5.play.js:6097

When checking for tunneling through a OrientedBoundingBoxCollider use a worst-case of zero (e.g. if the other sprite is passing through a corner).

Parameters:

Returns:

Number
_getRadiusOnAxis
(
  • axis
)
Number
protected

Inherited from p5.CollisionShape but overwritten in lib/p5.play.js:6085

Get this shape's radius (half-width of its projection) along the given axis.

Parameters:

Returns:

Number
_onTransformChanged ()
protected

Inherited from p5.CollisionShape but overwritten in lib/p5.play.js:6014

Recalculate cached properties, relevant vectors, etc. when at least one of the shape's transforms changes. The base CollisionShape (and PointCollider) only need to recompute the shape's center, but other shapes may need to override this method and do additional recomputation.

collide
(
  • other
)
p5.Vector

Compute the smallest movement needed to move this collision shape out of another collision shape. If the shapes are not overlapping, returns a zero vector to indicate that no displacement is necessary.

Parameters:

Returns:

draw
(
  • sketch
)

Defined in lib/p5.play.js:6047

Debug-draw this collider.

Parameters:

  • sketch P5
    • p5 instance to use for drawing
getBoundingBox () Top: number, bottom: number, left: number, right: number, width: number, height: number

Get world-space axis-aligned bounds information for this collision shape. Used primarily for the quadtree.

Returns:

Top: number, bottom: number, left: number, right: number, width: number, height: number:

}

overlap
(
  • other
)
Boolean

Check whether this shape overlaps another.

Parameters:

Returns:

Boolean
setParentTransform
(
  • parent
)

Update this collider's parent transform, which will in turn adjust its position, rotation and scale in world-space and recompute cached values if necessary. If a Sprite is passed as the 'parent' then a new transform will be computed from the sprite's position/rotation/scale and used.

Parameters:

updateFromSprite
(
  • sprite
)

Inherited from p5.CollisionShape but overwritten in lib/p5.play.js:5977

Update this collider based on the properties of a parent Sprite.

Parameters:

updateSweptColliderFromSprite
(
  • sprite
)

Defined in lib/p5.play.js:5986

Assuming this collider is a sprite's swept collider, update it based on the properties of the parent sprite so that it encloses the sprite's current position and its projected position.

Parameters:

Properties

_center

p5.Vector private

The center of the collision shape in world-space.

_halfDiagonals

Array. private

Defined in lib/p5.play.js:5889

Cached half-diagonals, used for computing a projected radius. Already transformed into world-space.

_localTransform

p5.Transform2D protected

Transform of this shape relative to its parent. If there is no parent, this is pretty much the world-space transform. This should stay consistent with _offset, _rotation and _scale properties.

_offset

p5.Vector private

The center of the collision shape in local-space; also, the offset of the collision shape's center from its parent sprite's center.

_parentTransform

p5.Transform2D protected

Transform of whatever parent object (probably a sprite) this shape is associated with. If this is a free-floating shape, the parent transform will remain an identity matrix.

_potentialAxes

Array. private

Defined in lib/p5.play.js:5881

Cached separating axes this shape contributes to a collision.

_rotation

Number private

Rotation in radians in local space (relative to parent). Note that this will only be meaningful for shapes that can rotate, i.e. Oriented Bounding Boxes

_scale

p5.Vector private

Scale X and Y in local space. Note that this will only be meaningful for shapes that have dimensions (e.g. not for point colliders)

_width

Number private

Defined in lib/p5.play.js:5865

Unscaled box width.

_width

Number private

Defined in lib/p5.play.js:5873

Unscaled box height.

center

p5.Vector

The center of the collision shape in world-space. Note: You can set this property with a value in world-space, but it will actually modify the collision shape's local transform.

getsDimensionsFromSprite

Boolean

If true, when calling updateFromSprite this collider will adopt the base dimensions of the sprite in addition to adopting its transform. If false, only the transform (position/rotation/scale) will be adopted.

halfDiagonals

Array.

Defined in lib/p5.play.js:5934

Two vectors representing adjacent half-diagonals of the box at its current dimensions and orientation.

height

Number

Defined in lib/p5.play.js:5917

The unrotated height of the box collider. Recomputes diagonals when set.

offset

p5.Vector

The center of the collision shape in local-space - if this collider is owned by a sprite, the offset of the collider center from the sprite center.

rotation

Number

The local-space rotation of the collider, in radians.

scale

p5.Vector

The local-space scale of the collider

width

Number

Defined in lib/p5.play.js:5900

The unrotated width of the box collider. Recomputes diagonals when set.

Static Methods

p5.OrientedBoundingBoxCollider.createFromSprite
(
  • sprite
  • offset
  • width
  • height
  • rotation
)
p5.CircleCollider

Defined in lib/p5.play.js:5953

Construct a new AxisAlignedBoundingBoxCollider with given offset for the given sprite.

Parameters:

  • sprite Sprite
  • [offset] p5.Vector optional

    from the sprite's center

  • [width] Number optional
  • [height] Number optional
  • [rotation] Number optional

    in radians