Collider:collisions

Returns all components currently colliding with this collider.

Usage

collider:collisions()

Returns

Name Type Description
collisions table A table where every key is a Collider or Sensor, and the values are their owning entities.

Examples

local ecs = crystal.ECS:new();
local physics_system = ecs:add_system(crystal.PhysicsSystem);

local hero = ecs:spawn(crystal.Entity);
hero:add_component(crystal.Body);
hero:add_component(crystal.Collider, love.physics.newCircleShape(4));
hero:set_categories("characters");
hero:enable_collision_with("level", "characters");

local monster = ecs:spawn(crystal.Entity);
monster:add_component(crystal.Body);
monster:add_component(crystal.Collider, love.physics.newCircleShape(8));
monster:set_categories("characters");
monster:enable_collision_with("level", "characters");

ecs:update();
physics_system:simulate_physics(0.01);

local component, entity = next(hero:collisions());
assert(entity == monster);
assert(component == monster:component(crystal.Collider));

This site uses Just the Docs, a documentation theme for Jekyll.