Coder Social home page Coder Social logo

appsinacup / godot-box2d Goto Github PK

View Code? Open in Web Editor NEW
291.0 4.0 9.0 5.62 MB

Godot Box2D – C++ Godot Extension that integrates the Box2D physics engine.

License: MIT License

Python 0.84% Shell 0.87% C++ 97.27% PowerShell 0.96% GDScript 0.07%
box2d box2d-physics-engine godot godot-4 godot-addon godot-plugin

godot-box2d's People

Contributors

rburing avatar ughuuu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

godot-box2d's Issues

Collision layers and masks don't work same as they do in Godot

Right now, in box2d, you can set a collision mask and category field.
In godot, you can do same, but in godot, if you have the following case:

object mask category
object A 1 2
object B 2 2

Then object B will interact with object A, but object A will not interact with object B. That is, object A will always continue it's path, as if no restitution is given to it after the collision.

This is a little bit difficult to do in box2d. Need to investigate more on how to do it.

Bug: Parent scaling not respected on CollisionPolygons

I noticed that it appears area2Ds do not like to be scaled with Box2D!

I've not tested how far this goes but I know the bug can be reproduced as follows:

Create a sprite
Add child area2D and debug_print things which should react to collisions like _body_just_entered(body)
Set up a collisionpolygon2d child so the area2D works
Set the original sprite's scale to 200 and throw some rigidbodies at it.

You will notice that the rigidbody responds as if it were unscaled, the polygon's visuals and actual detection are now mis-matched due to the scaling.

Investigate failing test where safe/unsafe fraction doesn't match

Failing test
DirectSpaceState2D | testing [cast_motion] from [get_world_2d().direct_space_state] > Can collide with Body

Test Description:

I have 2 shapes, shape_A and shape_B.
shape_A has motion 360.
shape_A is located at b2Vec2(5.76, 3.24)
shape_B motion 0.
shape_B is located at b2Vec2(11.52, 3.24)
tMax is 1.

After calling timeOfImpact, I find t = 0.014
Distance that shapeA traveled is is 5.05

After calling b2Distance at moment of impact, I get distance between two shapes = 11.57

[safe, unsafe]
[0.0126953125, 0.01416015625] - godot2d
[0.01255518198013, 0.01404166780412] - box2d

Torque and constant torque and angular rotation doesn't work same as it does in godot

There is some inconsistency in how I convert torque and inertia and other properties to godot, and when I get the torque, I am not conveting correctly and get different values if I rotate an object over a period of time:

Eg. the following physics tests that fails:

1. RigidBody2D | testing the basic API > Constant torque is applied
2. RigidBody2D | testing the basic API > The impulse torque is applied to the angular velocity
3. RigidBody2D | testing the basic API > The impulse torque makes the body rotate correctly

Sync to Physics tests fail

37. Sync to Physics | checks if the body is synced with the platform with Tween/AnimationPlayer > Tween with [sync_to_physics] pos y is sync
38. Sync to Physics | checks if the body is synced with the platform with Tween/AnimationPlayer > Animation Player with [sync_to_physics] pos x is sync
39. Sync to Physics | checks if the body is synced with the platform with Tween/AnimationPlayer > Animation Player with [sync_to_physics] pos y is sync
40. Sync to Physics | testing if [collision_animatable] sync body to the Tilemap2D platform > Tilemap with [sync_to_physics] pos x is sync
41. Sync to Physics | testing if [collision_animatable] sync body to the Tilemap2D platform > Tilemap with [sync_to_physics] pos y is sync

Not sure what these tests are about, but it seems the physics server is not in sync with something, even after a field that should make it so sets it explicitly. Need to investigate to see where that is set and what it should do.

Upgrade to box2c

Box2C or Box2D v3 is a rewrite of box2D to be faster, support new features(assert callback, capsule shape, id's instead of pointer for api when getting stuff, etc.).

When that's out we should definitely check integrating it back here.
Here is the repo link https://github.com/erincatto/box2c

Skewed or scaled shapes don't work

Skewed shapes don't work. Scaling also doesn't work on all shapes.
For square we should make it a polygon if it's skewed. For circle we should make it some kind of elipsis, for capsule?, etc
Note godot physics has support for this.

Zero friction physics material does not simulate

Creating a basic rigidbody with a physics material which has a friction value of 0 causes the rigidbody to stop all movement. Other bodies with higher friction values will still simulate in the same space, and will treat the body as static.

Constant Torque and Impulse Torque are applied differently

These tests are still failing, however I am not very invested to fix them, as the final values are very close:

1. RigidBody2D | testing the basic API > Constant torque is applied
2. RigidBody2D | testing the basic API > The impulse torque is applied to the angular velocity
3. RigidBody2D | testing the basic API > The impulse torque makes the body rotate correctly

Here are the value difference:

 Constant torque is applied : ✗ ☹ (regression)
Error: Constant torque is not applied correctly: expected 0.266667, get 0.291667
Error: Impulse torque is not applied correctly to the angular velocity: expected 4.800000, get 5.000000
Error: The impulse torque is not applied correctly to the rotation: expected 1.600000, get 1.666667

CharacterBody2D stick to floor doesn't work

Following test is failing on physics tests:

Snapping works as expected (stick to the floor)

Test Name:

CharacterBody2D | testing [floor floor_snap_length] [shape: Capsule] > Snapping works as expected (stick to the floor)

PinJoint2D angle limits work incorrectly if NodeB parent node turns 180 degrees.

Describe the bug
If PinJoint2D has limits enabled with the following node hierarchy

Scene
- NodeA (RigidBody2D)
  - PinJoint2D
  - NodeB (RigidBody2D)

then when NodeA node turns over 180 degrees the PinJoint2D will lose track of where the limits are and begin spinning.
However, if NodeB is not child of NodeA then the limits will work correctly.

image

To Reproduce
Using the attached project turn the box around with left/right keys. When turned 180 degrees it should fail.

Expected behavior
Expected that the physics behavior is not affected by the node hierarchy.

Project
PinJointAngleBug.zip

Versions (please complete the following information):

  • OS: Windows
  • Godot v4.2 beta6
  • Box2d v0.9.0

Fix character controller.

Right now it doesn't do the same as in godot, making it buggy. It needs to have 3 steps:

  1. Recover phase. Move the object(with margin) outside of any intersection.
  2. Cast motion(without margin) phase.
  3. Rest info(with margin) check if the body intersects again, but this time only to return intersection points.

Collision shapes behave as if they are bigger than what it should be

Describe the bug
CharacterBody2D collisions (I haven't tested other body types) behave like they are somewhat bigger than what shows with Visible Collision Shapes on.

Box2D/Rapier2D

off

To Reproduce
Steps to reproduce the behavior:

  1. Make a 2D platformer like the one above.
  2. Move the character to a wall and see the distance between the shapes.

Expected behavior
The same as the Rapier2D example above.

If this is intended at least could be documented

Versions (please complete the following information):

  • OS: [Ubuntu 22.04]
  • Godot [v4.2 beta5]
  • Box2d [v0.9.2]

rotation inconsistencies

Describe the bug
while the fix in #71 helped quite a bit, i still believe there is some weirdness in how rotations of bodies are handled.
Depending on how my AnimatableBody2D is rotated, i can observe anything from extreme velocity increases to clipping.
The master with #73 in particular is more erratic.

grafik

To Reproduce
Steps to reproduce the behavior:

  1. Open the scene and play
  2. press r to spawn pinballs over the left and right flipper
  3. interact with the marbles using shift or ctrl (shift is now a lower velocity flip, ctrl is higher velocity flip with initial delay)
  4. observe that the right flipper causes extreme velocity increases, sometimes flips by itself, and sometimes the marble clips through it
  5. stop play
  6. very slightly change the rotation of FlipperR in game GameScene.tscn from 142.6 down to 140.
  7. play again
  8. observe that the physics are working perfectly fine

Expected behavior
Consistent physics no matter how bodies are rotated

Project
If applicable, add a reproducible project to help explain your problem.
project_wild_rotations_2023_11_23_1.zip

Versions (please complete the following information):

  • OS: Windows
  • Godot v4.2.rc1.mono.official [ad72de508]
  • Box2d master with #73
  • Box2d master with #71 is "better" - however in that version the marble clips every single time through the right flipper on the ctrl flip (and also works perfectly fine when changing the rotation from 142.6 down to 140)

SegmentShape2D seems unsupported

Adding SegmentShape2D to a project with Box2D enabled crashes it. Enabling Box2D in a project with a SegmentShape2D in it crashes the editor.

I've attached a simple project that has basically nothing but a SegmentShape2D attached to a RigidBody2D, though I suspect this issue would come up in any project that uses a SegmentShape2D. Add the addon to this project, enable it, and it should cause the editor to crash (at least with version 4.1.1).

CollisionSegmentProblem.zip

Collision "recipients" unaffected by mass or bounce.

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)

Fix One Way Collision for rigidbodies

Tests:

1 Monitor(s) expected to fail:
2. CollisionShape2D | testing [One Way Collision] with RigidBody2D > Only collide if the platform rotation > 180°

body_entered collisions events are sometimes missed

Describe the bug
body_entered event of RigidBody2D is not always called when collision happens. This is frequent when the colliding body moves fast and bounces off a surface.

When comparing Godot Physics with Box2D it seems that Godot Physics always reports the collision successfully. However, with Box2D it is missed often. Most likely the event is not propagated to Godot side if the contact only happens during physics sub-stepping.

To Reproduce
Use the attached project. Play the scene. A ball is shot towards a wall and bounces off it. A message is printed when body_entered event is called for the ball.

Run it first with using Godot Physics. The message is always printed. Then try with Box2D. The message is usually not printed.

If you reduce the initial speed of the ball enough then the Box2D will also begin to print the message, but can still sometimes miss.

Expected behavior
Expected that body entered and exit events are reliably called as it does with Godot Physics.

Project
Attached test project
CollisionMissedBug.zip

Versions (please complete the following information):

  • OS: Windows 10
  • Godot v4.2 rc2
  • Box2d v0.9.2

Add Element on CollisionPolygon2D Polygon causes Godot to crash

Using "Add Element" on Polygon property of CollisionPolygon2D node almost always causes Godot to crash.

To Reproduce

  1. Create StaticBody2D node.
  2. Create CollisionPolygon2D node as child node.
  3. Select CollisionPolygon2D node to open the Inspector.
  4. (Optional) Create 3 or more points with mouse.
  5. Edit Polygon property by adding new points to it using "Add Element" button.
    This will crash Godot if there are 3 or more points.

Occasionally Godot will also crash when moving points using mouse.

Expected behavior
Godot does not crash when editing the shape.

Versions:

  • OS: Win 10
  • Godot v4.2 beta 3
  • Box2d v0.8

If PROCESS_MODE_DISABLED is set, no physics simulations happens

For Godot Physics, some physics simulations happens.

Eg. in the tests testing Continuous Collision Detection, they pass in Godot even though the line:

process_mode = Node.PROCESS_MODE_DISABLED

Test Names:

2. RigidBody2D | testing Continuous Collision Detection (CCD) > Rigid moving in x with CCD detects collision
3. RigidBody2D | testing Continuous Collision Detection (CCD) > Rigid moving in y with CCD detects collision
4. RigidBody2D | testing Continuous Collision Detection (CCD) > Rigid moving in x with CCD detects collision
5. RigidBody2D | testing Continuous Collision Detection (CCD) > Rigid moving in y with CCD detects collision

AnimatableBody2D gets rotated (inconsistently)

Describe the bug
I have a AnimatableBody2D that i rotate based in user input. (2 pinball flippers).
somehow, and only with bod2d enabled, one of them gets rotated by physics.

To Reproduce
Steps to reproduce the behavior:

  1. open the provided project
  2. press shift a few times to flip the paddles
  3. see that the right paddle gets rotated, while the left paddle stays within its intended rotations

Expected behavior
I expect the physics engine to never change the rotation of an AnimatableBody2D

Project
flippers_rotated_2023_11_19_1.zip
weird_rotation

is attached

Versions (please complete the following information):

  • OS: Windows
  • Godot v4.2.rc1.mono.official [ad72de508]
  • Box2d 0.9.1

Does this add-on support deterministic physics?

Out of curiosity, does Box2D (and this Godot integration) support deterministic physics? This should be noted in the README (even if it isn't), as this may be a reason to look for a third-party physics engine.

Area2D colliding with StaticBody2D - No Event

Hi, this is really cool and the physics seem 'better' than the default Godot 2D.

I am having an issue with getting any signals i.e. _on_body_entered() when an Area2D collides with a StaticBody2D.
It works fine with the Godot 2D Physics, but not with Box2D. Not sure if I am doing something wrong or this is a bug, or just the way Box2D works.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.