Hi! In own implementation of World (by extending it) I'm detecting by RayCast if there are some fixtures between 2 points:
Code:
var f:b2Fixture;
var b:b2Body;
var p1:V2 = new V2(line.startPoint.x / this.scale, line.startPoint.y / this.scale);
var p2:V2 = new V2(line.endPoint.x / this.scale, line.endPoint.y / this.scale);
var bodies:Vector.<b2Body> = new Vector.<b2Body>();
var cb = function(fixture:b2Fixture, point:V2, normal:V2, fraction:Number):Number{
f = fixture;
if (bodies.indexOf(f.GetBody()) == -1)
bodies.push(f.GetBody());
return fraction;
}
b2world.RayCast(cb, p1, p2);
trace("End of RC");
trace(bodies.length);
Then I'm copying detected dynamic bodies to vector:
Code:
for (var i:int = 0; i < bodies.length; i++ ) {
b = bodies[i];
if (b.GetType() == b2Body.b2_dynamicBody)
bodiesToDestroy.push(b);
}
After timestep doing this:
Code:
while (bodiesToDestroy.length > 0) {
var b:b2Body = bodiesToDestroy.pop();
if (b != null) {
removeChild(b.GetUserData());
b2world.DestroyBody(b);
b = null;
}
}
It works fine until I delete the last dynamic body (or sometimes randomly?). The error is
Code:
Assertion failed: (m_bodyCount > 0), function DestroyBody, file ../Box2D/Dynamics/b2World.cpp, line 129.
[object AlchemyExit]
at Function/<anonymous>()
at Function/<anonymous>()
at Box2DAS.Dynamics::b2Body/destroy()
at Box2DAS.Dynamics::b2World/DestroyBody()
at GWorld/step()
Cannot display source code at this location.
For some strange reason, RayCast isn't accurate. I can draw a line (with 2 points: startPoint and endPoint) above 2 bodies, but RayCast returns only one body. StartPoint is outside of body...