diff --git a/CHANGELOG.md b/CHANGELOG.md index ba628da..7916840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ ## [v0.5](https://github.com/godot-box2d/godot-box2d/releases/tag/v0.5) -- Fix shapes not updating(changing shape geometry) -- Fix deleting shapes/body/spaces bug +- Fix [shapes not updating(changing shape geometry)](https://github.com/godot-box2d/godot-box2d/issues/16) +- Fix [deleting shapes/body/spaces bug](https://github.com/godot-box2d/godot-box2d/issues/18) +- Possible fix for [collision between static body and area bug](https://github.com/godot-box2d/godot-box2d/issues/19) ## [v0.4](https://github.com/godot-box2d/godot-box2d/releases/tag/v0.4) diff --git a/README.md b/README.md index 6683c43..f5136b3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ A [box2D](https://github.com/erincatto/box2d) physics server for [Godot Engine](https://github.com/godotengine/godot) 4.1, implemented as a GDExtension. +Currently passes 127/150 of [Godot-Physics-Tests](https://github.com/fabriceci/Godot-Physics-Tests). + +## Determinism + +Box2D is binary deterministic, but doesn't make any guaratee as for cross platform determinism. +Godot Box2D should also be binary deterministic, however no such tests were run yet. +However, when Box2C gets released, that will be one of this repo's goals to make it cross platform deterministic (from what I spoke to Erin, it should be just the cos and sin functions that are not determinstic). + ## Limitations - Having non symetrical physics mask/layers results in no collision. Eg. if we had the following: diff --git a/src/joints/box2d_joint.cpp b/src/joints/box2d_joint.cpp index ddd5346..e62320b 100644 --- a/src/joints/box2d_joint.cpp +++ b/src/joints/box2d_joint.cpp @@ -73,8 +73,7 @@ void Box2DJoint::make_pin(const Vector2 &p_anchor, Box2DBody *p_body_a, Box2DBod joint_def = revolute_joint_def; common.body_a = p_body_a; common.body_b = p_body_b; - // body_a and body_b are set when joint is created - configured = true; + configured = common.body_a && common.body_b; } void Box2DJoint::make_groove(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, Box2DBody *p_body_a, Box2DBody *p_body_b) { @@ -90,8 +89,7 @@ void Box2DJoint::make_groove(const Vector2 &p_a_groove1, const Vector2 &p_a_groo joint_def = prismatic_joint_def; common.body_a = p_body_a; common.body_b = p_body_b; - // body_a and body_b are set when joint is created - configured = true; + configured = common.body_a && common.body_b; } void Box2DJoint::make_damped_spring(const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, Box2DBody *p_body_a, Box2DBody *p_body_b) { @@ -104,8 +102,7 @@ void Box2DJoint::make_damped_spring(const Vector2 &p_anchor_a, const Vector2 &p_ joint_def = distance_joint_def; common.body_a = p_body_a; common.body_b = p_body_b; - // body_a and body_b are set when joint is created - configured = true; + configured = common.body_a && common.body_b; } void Box2DJoint::set_pin_softness(real_t p_softness) { @@ -121,7 +118,7 @@ void Box2DJoint::set_damped_spring_rest_length(real_t p_damped_spring_rest_lengt return; } damped_spring.rest_length = godot_to_box2d(p_damped_spring_rest_length); - if (joint && (b2DistanceJoint *)joint) { + if (joint) { b2DistanceJoint *distance_joint = (b2DistanceJoint *)joint; distance_joint->SetLength(damped_spring.rest_length); } @@ -135,7 +132,7 @@ void Box2DJoint::set_damped_spring_stiffness(real_t p_damped_spring_stiffness) { return; } damped_spring.stiffness = godot_to_box2d(p_damped_spring_stiffness); - if (joint && (b2DistanceJoint *)joint && common.body_a && common.body_b) { + if (joint && common.body_a && common.body_b) { b2DistanceJoint *distance_joint = (b2DistanceJoint *)joint; float stiffness = 0; float damping = 0; @@ -152,7 +149,7 @@ void Box2DJoint::set_damped_spring_damping(real_t p_damped_spring_damping) { return; } damped_spring.damping = godot_to_box2d(p_damped_spring_damping); - if (joint && (b2DistanceJoint *)joint && common.body_a && common.body_b) { + if (joint && common.body_a && common.body_b) { b2DistanceJoint *distance_joint = (b2DistanceJoint *)joint; float stiffness = 0; float damping = 0; @@ -172,6 +169,10 @@ Box2DBody *Box2DJoint::get_body_b() { } b2JointDef *Box2DJoint::get_b2JointDef() { + if (!common.body_a || !common.body_b) { + WARN_PRINT("Cannot configure joint. Missing one body."); + return joint_def; + } switch (type) { case PhysicsServer2D::JointType::JOINT_TYPE_PIN: { b2RevoluteJointDef *revolute_joint_def = (b2RevoluteJointDef *)joint_def; @@ -184,6 +185,7 @@ b2JointDef *Box2DJoint::get_b2JointDef() { distance_joint_def->Initialize(common.body_a->get_b2Body(), common.body_b->get_b2Body(), common.anchor_a, common.anchor_b); distance_joint_def->length = damped_spring.rest_length; + distance_joint_def->minLength = 0; } break; case PhysicsServer2D::JointType::JOINT_TYPE_GROOVE: { b2PrismaticJointDef *prismatic_joint_def = (b2PrismaticJointDef *)joint_def; diff --git a/src/servers/physics_server_box2d.cpp b/src/servers/physics_server_box2d.cpp index ddfc322..9fe65fd 100644 --- a/src/servers/physics_server_box2d.cpp +++ b/src/servers/physics_server_box2d.cpp @@ -983,7 +983,7 @@ bool PhysicsServerBox2D::_body_collide_shape(const RID &p_body, int32_t p_body_s } Box2DDirectSpaceState *space_state = (Box2DDirectSpaceState *)body->get_space_state(); ERR_FAIL_COND_V(!space_state, false); - return space_state->_collide_shape(shape->get_self(), p_shape_xform, p_motion, 0, body->get_collision_mask(), true, true, p_results, p_result_max, p_result_count); + return space_state->_collide_shape(shape->get_self(), p_shape_xform, p_motion, 0, body->get_collision_mask(), true, false, p_results, p_result_max, p_result_count); } void PhysicsServerBox2D::_body_set_pickable(const RID &p_body, bool p_pickable) { Box2DBody *body = body_owner.get_or_null(p_body); @@ -1001,8 +1001,8 @@ bool PhysicsServerBox2D::_body_test_motion(const RID &p_body, const Transform2D shapes.append(shape); } - Vector query_result = Box2DSweepTest::query_aabb_motion(shapes, p_from, p_motion, p_margin, 0xff, true, true, (Box2DDirectSpaceState *)body->get_space_state()); - Vector sweep_test_results = Box2DSweepTest::multiple_shapes_cast(shapes, p_from, p_motion, p_margin, 0xff, true, true, 2048, query_result, (Box2DDirectSpaceState *)body->get_space_state()); + Vector query_result = Box2DSweepTest::query_aabb_motion(shapes, p_from, p_motion, p_margin, 0xff, true, false, (Box2DDirectSpaceState *)body->get_space_state()); + Vector sweep_test_results = Box2DSweepTest::multiple_shapes_cast(shapes, p_from, p_motion, p_margin, 0xff, true, false, 2048, query_result, (Box2DDirectSpaceState *)body->get_space_state()); SweepTestResult sweep_test_result = Box2DSweepTest::closest_result_in_cast(sweep_test_results); PhysicsServer2DExtensionMotionResult ¤t_result = *p_result; if (!sweep_test_result.collision) {