Sensor:on_activate

Called when a collider or sensor starts overlapping this sensor. Default implementation does nothing.

Usage

sensor.on_activate = function(self, other_component, other_entity, contact)
  -- your code here
end

Arguments

Name Type Description
other_component Sensor or Sensor Components this sensor is overlapping with.
other_entity Entity Entity activating the sensor, owner of other_component.
contact love.Contact Contact generated by the overlap.

As the LOVE documentation recommends:

The lifetimes of Contacts are short. When you receive them in callbacks, they may be destroyed immediately after the callback returns. Cache their values instead of storing Contacts directly.

Examples

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

local healing_shrine = ecs:spawn(crystal.Entity);
healing_shrine:add_component(crystal.Body);
local sensor = coin:add_component(crystal.Sensor, love.physics.newRectangle(100, 100));
healing_shrine:set_categories("powerups");
healing_shrine:enable_collision_with("characters");

sensor.on_activate = function(self, other_component, other_entity, contact)
  other_entity:enable_shrine_regen();
end

sensor.on_deactivate = function(self, other_component, other_entity, contact)
  other_entity:disable_shrine_regen();
end

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