appsinacup / godot-box2d Goto Github PK
View Code? Open in Web Editor NEWGodot Box2D – C++ Godot Extension that integrates the Box2D physics engine.
License: MIT License
Godot Box2D – C++ Godot Extension that integrates the Box2D physics engine.
License: MIT License
The Shapecast2D node does not seem to detect collisions. I've attached a project that prints to console when hits are detected. Note that it works with Godot physics but not Box2D.
Box2DTests.zip
Game crashing after click TouchScreenButton with box2d
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.
scale rn works from shape only.
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.
Failing test
DirectSpaceState2D | testing [cast_motion] from [get_world_2d().direct_space_state] > Can collide with Body
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
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
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.
Is the DampedSpringJoint2D implemented/tested in this version?
For me it's as buggy as in godot physics, completely unusable. Any change in the settings and it glitches.
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
Calling apply_impulse ignores the objects mass, and also introduces a significant amount of angular motion.
I've attached a small repo for reproduction. One circle has a mass of 1000, the other 1. Observe that when impulse is applied by clicking anywhere, both start spinning and have an equal amount of force applied.
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.
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.
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
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)
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.
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):
Right now it doesn't do the same as in godot, making it buggy. It needs to have 3 steps:
The following test is failing: Area2D | testing the basic API > Don't detect rigid body on collision layer 2
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.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The same as the Rapier2D example above.
If this is intended at least could be documented
Versions (please complete the following information):
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.
To Reproduce
Steps to reproduce the behavior:
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):
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).
Linked issue from Godot-cpp godotengine/godot-cpp#554
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 ❌
Here I have uploaded a test scene. The scene should look like this:
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)
I tried to add it here:https://github.com/godot-box2d/godot-box2d/actions/runs/5666594823
But got error:
Built-in type config: float_32
In file included from include/godot_cpp/core/memory.hpp:34,
from src/core/memory.cpp:31:
/usr/include/c++/9/cstddef:49:10: fatal error: bits/c++config.h: No such file or directory
49 | #include <bits/c++config.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Behaviour should be that bodies that touch them should gain velocity, like a conveyer belt
Tests:
1 Monitor(s) expected to fail:
2. CollisionShape2D | testing [One Way Collision] with RigidBody2D > Only collide if the platform rotation > 180°
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):
Using "Add Element" on Polygon property of CollisionPolygon2D node almost always causes Godot to crash.
To Reproduce
Occasionally Godot will also crash when moving points using mouse.
Expected behavior
Godot does not crash when editing the shape.
Versions:
ray edge cases.
safe/unsafe ratio edge cases.
The object references are not deleted(eg. bodies, shapes, etc)
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
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:
Expected behavior
I expect the physics engine to never change the rotation of an AnimatableBody2D
Project
flippers_rotated_2023_11_19_1.zip
is attached
Versions (please complete the following information):
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.
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,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.