Function bevy::sprite::collide_aabb::collide

pub fn collide(
    a_pos: Vec3,
    a_size: Vec2,
    b_pos: Vec3,
    b_size: Vec2
) -> Option<Collision>
Expand description

Axis-aligned bounding box collision with “side” detection

  • a_pos and b_pos are the center positions of the rectangles, typically obtained by extracting the translation field from a Transform component
  • a_size and b_size are the dimensions (width and height) of the rectangles.

The return value is the side of B that A has collided with. Left means that A collided with B’s left side. Top means that A collided with B’s top side. If the collision occurs on multiple sides, the side with the deepest penetration is returned. If all sides are involved, Inside is returned.