crystal.Body
A Component representing an entity’s position in space and other physics parameters. Entities should have at most one Body component.
Constructor
Like all other components, Body components are created by calling Entity:add_component. The constructor expects one arguments: a love.BodyType for the underlying love.Body. If unspecified, the body type defaults to "dynamic".
entity:add_component(crystal.Body);
Methods
| Name | Description | |
|---|---|---|
| apply_impulse | Applies a linear impulse to the underlying love.Body. | |
| attach_to | Links this entity to another one, relinquishing control of its position. | |
| damping | Returns the linear damping of the underlying love.Body. | |
| detach_from_parent | Unlinks this entity from any parent it was attached to. | |
| distance_squared_to_entity | Returns the squared of the distance between this entity and another one. | |
| distance_squared_to | Returns the square of the distance between this entity and a specific location. | |
| distance_to_entity | Returns the distance between this entity and another one. | |
| distance_to | Returns the distance between this entity and a specific location. | |
| look_at | Sets this entity’s rotation so that it faces a specific location. | |
| position | Returns this entity’s position. | |
| rotation | Returns this entity’s rotation. | |
| set_damping | Sets the linear damping of the underlying love.Body. | |
| set_position | Sets this entity’s position. | |
| set_rotation | Sets this entity’s rotation. | |
| set_velocity | Sets the linear velocity of the underlying love.Body. | |
| velocity | Returns the linear velocity of the underlying love.Body. |
Examples
local ecs = crystal.ECS:new();
ecs:add_system(crystal.PhysicsSystem);
local monster_positions = {
{100, 200},
{40, 87},
{-100, 130},
};
for _, position in ipairs(monster_positions) do
local monster = ecs:spawn(crystal.Entity);
monster:add_component(crystal.Body);
monster:set_position(position[1], position[2]);
end