appsinacup / godot-box2d

Godot Box2D – C++ Godot Extension that integrates the Box2D physics engine.
MIT License
324 stars 14 forks source link

When "rough" is checked and friction differs, collision causes objects to disappear #110

Open pthrasher opened 5 months ago

pthrasher commented 5 months ago

Describe the bug When physics materials differ in 2d collisions, and rough is checked on one of the materials, collision happens, and then the body appears to be removed from the world.

To Reproduce Steps to reproduce the behavior:

  1. make a rigidbody2d and add a new physics material with < 1 friction.
  2. make a static body and add a new physics material with a greater friction from above, and check "rough"
  3. allow rigid body to freely fall onto static body.

Expected behavior I expected the rigidbody to appropriately react to the static body rather than disappearing.

Project PhysMatProblem.zip

Versions (please complete the following information):

MrEgggga commented 4 months ago

it seems like box2d's friction calculation works completely different from godot physics's calculation such that the "rough" field means nothing. if you do need the roughness feature it seems like you'd have to compile your own version of box2d (although it seems like this wouldn't be too hard -- box2d's friction calculation is about one line long). in any case, though, the thing definitely shouldn't fail in the way it does. i'm planning on modifying this extension for my own game so i might be able to figure out why that happens.

MrEgggga commented 4 months ago

i think i've figured it out:

there are two solutions to this:

  1. change the box2d wrapper to give box2d the absolute value of the computed friction so we don't have to worry about negative values. this is probably the best solution for the main version of this extension. i'll probably make a pull request for this tomorrow-ish.
  2. make a fork of box2d that changes its friction calculation to work like godot physics. this is good if you want to keep the "rough surfaces" feature, but not what should be done for this version of the repository. i'm planning on doing this for my game.