ByteArena / box2d

Box2D.go - Go port of Box2D - a 2D Physics Engine for Games.
Other
295 stars 48 forks source link

Simulation instability caused by some joints #9

Closed maxfish closed 6 years ago

maxfish commented 6 years ago

It looks like some of the joints types don't work properly.

I'm implementing a loader for R.U.B.E scenes here https://github.com/maxfish/gojira2d/blob/master/pkg/physics/b2djson_scene.go and I'm trying a lot of different scenes. I can see that the only joints which work well are revolute, rope, distance and wheel. Motor, prismatic, weld and friction seem to make the simulation explode after a while.

Here is one example of a weld join that is unstable: https://pastebin.com/dPB2xBfV As soon as body3, while falling, touches body2, body2 sprints away from the screen at high speed

Another example simulating a R.U.B.E scene containing all types of joints:

Any ideas of what could be the cause?

maxfish commented 6 years ago

Found a code error for the Prismatic joints when warmStart is true. I've fixed it in my fork https://github.com/maxfish/box2d/commit/a623c1c17307645c2d47ba55875056de0776956f

xtuc commented 6 years ago

Nice! would you mind doing a PR?

maxfish commented 6 years ago

Here it is #10 Unfortunately, the other issues are still there. I'll keep checking

maxfish commented 6 years ago

After the fixes I've submitted via PRs (including the changes suggested in #7), it looks like the joints (weld, revolute, prismatic, friction, motor, distance, rope, wheel) work as expected.

Here there is an updated video: https://youtu.be/zo81uKfpTzQ

maxfish commented 6 years ago

I'm closing this since the issue seems to be fixed now