I've talked too fast. Sometimes the ball seems to get balls beyond the range and other times, when there is a unique body in the range, this body is not detected.
Here's my code :
Code:
public function joinBodiesInRange( $body:b2Body, $radius:Number ) : void
{
var aabbAnchor:b2AABB = new b2AABB( );
aabbAnchor.lowerBound.Set( $body.GetPosition().x - $radius / PHYS_SCALE, $body.GetPosition().y - $radius / PHYS_SCALE );
aabbAnchor.upperBound.Set( $body.GetPosition().x + $radius / PHYS_SCALE, $body.GetPosition().y + $radius / PHYS_SCALE );
var circleShape:b2CircleShape = new b2CircleShape( $radius );
circleShape.SetLocalPosition( $body.GetPosition() );
function getBodyCallback( fixture:b2Fixture ) : Boolean
{
var body:b2Body = fixture.GetBody( );
if ( body != $body )
{
var shape:b2Shape = fixture.GetShape( );
if ( b2Shape.TestOverlap( circleShape, $body.GetTransform( ), shape, body.GetTransform( ) ) )
{
var distanceJoint:b2DistanceJointDef = new b2DistanceJointDef( );
distanceJoint.Initialize( $body, body, $body.GetPosition( ), body.GetPosition( ) );
_world.CreateJoint( distanceJoint );
}
}
return true;
}
_world.QueryAABB( getBodyCallback, aabbAnchor );
}