I've created a b2LoopShape that resembles a cup and I shoot golf ball(s) until it/they enter the cup. I want to be able to receive a single notification that the ball has entered and stayed in the cup successfully. I've used the following successfully, but when two balls enter the cup, only one (the smaller one) traces correctly (trace output occurs twice actually). The overridden PreSolve of the b2ContactListener is...
In my testing only the smaller ball seems to reach a LinearVelocity of (0,0), while the contactListener seems to end before the bigger ball reaches a LinearVelocity of (0,0). I tried setting the IsSleepingAllowed boolean of the golf balls to false (in an effort to keep getting contact events), but then the LinearVelocity of neither reaches (0,0). Any ideas or suggestions for better approaches would be much appreciated.
Is there a better way to figure this out? And I've checked, c.GetFixtureB() is always a golfball and c.GetFixtureA() is the "GroundHole_1".
Code:
override public function PreSolve(c:b2Contact, o:b2Manifold):void
{
//8 as index of end of "GolfBall"
var ballStr = String(c.GetFixtureB().GetBody().GetUserData().costume.name).slice(0, 8);
if (ballStr == "GolfBall" && c.GetFixtureA().GetBody().GetUserData().costume.name == "GroundHole_1")
{
if (c.GetFixtureB().GetBody().GetLinearVelocity().x == 0 && c.GetFixtureB().GetBody().GetLinearVelocity().y == 0)
{
trace("Made " + c.GetFixtureB().GetBody().GetUserData().costume.name + " in the hole!");
}
}
super.PreSolve(c, o);
}
{
//8 as index of end of "GolfBall"
var ballStr = String(c.GetFixtureB().GetBody().GetUserData().costume.name).slice(0, 8);
if (ballStr == "GolfBall" && c.GetFixtureA().GetBody().GetUserData().costume.name == "GroundHole_1")
{
if (c.GetFixtureB().GetBody().GetLinearVelocity().x == 0 && c.GetFixtureB().GetBody().GetLinearVelocity().y == 0)
{
trace("Made " + c.GetFixtureB().GetBody().GetUserData().costume.name + " in the hole!");
}
}
super.PreSolve(c, o);
}
In my testing only the smaller ball seems to reach a LinearVelocity of (0,0), while the contactListener seems to end before the bigger ball reaches a LinearVelocity of (0,0). I tried setting the IsSleepingAllowed boolean of the golf balls to false (in an effort to keep getting contact events), but then the LinearVelocity of neither reaches (0,0). Any ideas or suggestions for better approaches would be much appreciated.
Is there a better way to figure this out? And I've checked, c.GetFixtureB() is always a golfball and c.GetFixtureA() is the "GroundHole_1".