Collision response is different from Box2D
See original GitHub issueI work on a client/server game. The server uses the original Box2D implementation, and the client uses planck.js. I had some major differences in collision response between Box2D and planck. the test involves a (circle) bullet bouncing on a (circle) static body.
I identified the issue in the getWorldManifold function. I’ve only worked on circles for now, but the implementation in planck is different from the one in Box2D
var pointA = Transform.mulVec2(xfA, this.localPoint);
var pointB = Transform.mulVec2(xfB, this.points[0].localPoint);
var dist = Vec2.sub(pointB, pointA);
if (Vec2.lengthSquared(dist) > Math.EPSILON * Math.EPSILON) {
normal.set(dist);
normal.normalize();
}
points[0] = Vec2.mid(pointA, pointB);
separations[0] = -radiusB - radiusA;
First I had not seen this so it’s probably valid, I was testing outside of planck.Math.EPSILON
does not exists and the right value should be Number.EPSILON
(with a needed polyfill for Internet Explorer)
The end of the code should also be something like this:
var cA = pointA.clone().addMul(radiusA, normal);
var cB = pointB.clone().addMul(-radiusB, normal);
points[0] = Vec2.mid(cA, cB);
separations[0] = Vec2.dot(Vec2.sub(cB, cA), normal);
Replacing the code got me the expected result (similar collision response as Box2D)
Is there any reason the implementation in planck looks so wrong? Could it be changed?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Oh, very nice, I’ll idle there then 👍
Merged, thank you @FlorentMasson !