NAME

Collision::2D::Entity - A moving entity. Don't use this directly.

DESCRIPTION

ATTRIBUTES

x,y,xv,yv

Absolute position and velocity in space. These are necessary if you want to do collisions through dynamic_collision

dynamic_collision($circ1, $circ2);

relative_x, relative_y, relative_xv, relative_yv

You shouldn't worry about these. Move along now.

Relative position and velocity in space. these are necessary if you want to do collisions directly through entity methods,

$circ1->_collide_circle($circ2);

In this case, both the absolute and relative position and velocity of $circ2 is not used. The relative attributes of $circ1 are assumed to be relative to $circ2.

METHODS

collide

my $collision = $self->collide ($other_entity, interval=>4);

Detect collision with another entity. $self must be normalized to $other. Takes interval as a parameter. Returns a collision if there is a collision. Returns undef if there is no collision.

With the collide method, the entity order is preserved. Consider this example:

my $collision1 = $panel->collide($droplet);
my $collision2 = $droplet->collide($panel);

If these objects collide, then its $collision1-ent1> will be $panel, and $collision2-ent1> will be $droplet.

intersect

my $t_or_f = $self->intersect ($other_entity);

Detect intersection (overlapping) with another entity. Takes interval as a parameter. Returns a collision if there is a collision. Returns undef if there is no collision.

Relative vectors and velocity are not considered for intersection.

normalize

You probably shouldn't use this directly. At all. Relative vectors are handled automatically in dynamic_collision and in $ent1-collide($ent2)>

$self->normalize($other); # $other isa entity

This compares the absolute attributes of $self and $other. It only sets the relative attributes of $self. This is necessary to call _collide_*($other) methods on $self.