appsinacup / godot-box2d

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

Collision "recipients" unaffected by mass or bounce. #78

Closed awardell closed 9 months ago

awardell commented 9 months ago

Two RigidBody2D objects collide: stationary object A and moving object B. Object A's resultant velocity from this collision should vary based on mass of A and mass of B. Object B's resultant velocity does vary based on mass of A and B, but ✔ Object A's resultant velocity will not vary regardless of the mass of A or B ❌

GodotBox2DTest.zip

Here I have uploaded a test scene. The scene should look like this:

image

When run, the left bodies begin with velocity and will crash into the right bodies. The red bodies are heavier, and the green bodies are bouncier.

The project initially is set to use Godot's built-in physics server. Running the scene should show the expected behavior, which is that the heavier red bodies will not be moved as much as the lighter bodies.

Switch the project to use Box2D and then run the scene again. Observe now that the stationary bodies will all have the same resultant velocities regardless of their mass or of the bounciness of their materials. The initially-moving bodies, however, are correctly affected by the bounciness and by the mass of the body struck.

While using Box2D, changing the mass of the initially-moving bodies has no effect on the resultant velocity of the stationary bodies.

System Info: Godot v4.2.rc (5df986796) Windows 10.0.19045 Vulkan (Forward+) dedicated NVIDIA GeForce GTX 1080 Ti (NVIDIA; 31.0.15.3623) AMD Ryzen Threadripper 1950X 16-Core Processor (32 Threads) Box2d v0.9.2 (Downloaded from AssetLib)

Ughuuu commented 9 months ago

Seems to be I was doing the logic for conveyer belts(for static bodies) for all body types. This is why when a dynamic body touched another dynamic body, it would set its velocity to the other. Fixed in PR.

Ughuuu commented 9 months ago

Thanks for reporting it.

awardell commented 9 months ago

Fast fix! Thank you!