ExCollision.World.Body
(ExCollision v1.1.0)
View Source
Dynamic body in the collision world (AABB + metadata).
Implements the Collidable protocol.
Player and other moving objects are Body in the world, not MapObject. MapObject — static objects from TMX (objectgroup); Body — dynamic bodies with velocity and interpolation.
Option :on_collision — function (world, body_id, collided_ids, hit_static) -> world,
called on collision; can remove body (bullet), apply damage, etc.
(world, body_id, collided_body_ids, hit_static) -> world
world — current world
body_id — id of the body that collided
collided_body_ids — list of body ids that were hit (e.g. players)
hit_static — true if collision with static (wall, etc.)
Summary
Functions
AABB center (for rendering)
Interpolated center position for smooth rendering. alpha in [0, 1]: 0 = previous frame, 1 = current frame. If previous_aabb is nil, returns current center.
Interpolated top-left corner (min_x, min_y). Options: :clamp — clamp alpha to [0, 1].
Set collision callback: (world, body_id, [body ids], hit_static) -> world
Clear velocity
Set body velocity (vx, vy) in pixels/sec
Types
@type t() :: %ExCollision.World.Body{ aabb: ExCollision.Geometry.AABB.t(), data: term(), id: term(), on_collision: collision_callback() | nil, previous_aabb: ExCollision.Geometry.AABB.t() | nil, static: boolean(), velocity: {float(), float()} | nil }
Functions
AABB center (for rendering)
Interpolated center position for smooth rendering. alpha in [0, 1]: 0 = previous frame, 1 = current frame. If previous_aabb is nil, returns current center.
Options:
:clamp— iftrue, clampsalphato[0, 1]before interpolating (defaultfalse).
Interpolated top-left corner (min_x, min_y). Options: :clamp — clamp alpha to [0, 1].
Set collision callback: (world, body_id, [body ids], hit_static) -> world
Clear velocity
Set body velocity (vx, vy) in pixels/sec