Body:distance_to_entity

Returns the distance between this entity and another one. The other entity must have a Body component.

Usage

body:distance_to_entity(other_entity)

Arguments

Name Type Description
other_entity Entity Entity whose distance to should be measured.

Returns

Name Type Description
distance number Distance to the other entity.

Examples

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

local hero = ecs:spawn(crystal.Entity);
hero:add_component(crystal.Body);
hero:set_position(0, 0);

local coin = ecs:spawn(crystal.Entity);
coin:add_component(crystal.Body);
coin:set_position(10, 0);

print(hero:distance_to_entity(coin)); -- Prints "10"

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