Skip to main content

collide

Function collide 

Source
pub fn collide(
    axis: Axis,
    entity_aabb: &WorldAabb,
    shapes: &[WorldAabb],
    desired_movement: f64,
) -> f64
Expand description

Computes the maximum safe movement along an axis for an entity AABB through a list of obstacle shapes.

This is the core collision function used by vanilla’s Shapes.collide().

§Arguments

  • axis - The axis along which to move (X, Y, or Z)
  • entity_aabb - The entity’s current bounding box
  • shapes - List of obstacle shapes (block collision boxes) to test against
  • desired_movement - The desired movement distance along the axis

§Returns

The maximum safe movement that won’t cause collision (may be less than desired_movement). Returns the input value if no collision occurs.

§Algorithm

For each obstacle AABB, check if the entity AABB (moved by desired_movement on the given axis) would intersect on the other two axes. If so, clip the movement to stop at the obstacle’s face.

Matches: net.minecraft.world.phys.shapes.Shapes.collide(Direction.Axis, AABB, List<AABB>, double)