Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Aug 13, 2023
1 parent d23e87d commit 760f5b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
branch = 4.1
[submodule "box2d"]
path = box2d
url = https://github.com/godot-box2d/box2d
url = https://github.com/appsinacup/box2d
branch = common-assert-noop
[submodule "Godot-Physics-Tests"]
path = Godot-Physics-Tests
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ NOTE: the simulation for box2d goes slower (eg. 30 fps), while for godot physics

*Note*: The `template_debug` target can also be loaded in the Godot editor.

## How to update submodule

```
git submodule foreach git pull
```

## Lint

Run `scripts/clang-tidy.sh` in order to lint.
2 changes: 1 addition & 1 deletion src/shapes/box2d_shape_capsule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int Box2DShapeCapsule::get_b2Shape_count(bool is_static) const {
b2Shape *Box2DShapeCapsule::_get_transformed_b2Shape(ShapeInfo shape_info, Box2DCollisionObject *body) {
ERR_FAIL_INDEX_V(shape_info.index, 3, nullptr);
Vector2 scale = shape_info.transform.get_scale();
if (scale.x != scale.y) {
if (fabs(scale.x - scale.y) > b2_epsilon) {
ERR_PRINT("Capsules don't support non uniform scale.");
}
float radius_scaled = godot_to_box2d(radius * scale.x);
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/box2d_shape_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ b2Shape *Box2DShapeCircle::_get_transformed_b2Shape(ShapeInfo shape_info, Box2DC
ERR_FAIL_INDEX_V(shape_info.index, 1, nullptr);
b2CircleShape *shape = memnew(b2CircleShape);
Vector2 scale = shape_info.transform.get_scale();
if (scale.x != scale.y) {
if (fabs(scale.x - scale.y) > b2_epsilon) {
ERR_PRINT("Circles don't support non uniform scale.");
}
shape->m_radius = godot_to_box2d(radius * scale.x);
Expand Down
23 changes: 16 additions & 7 deletions src/spaces/box2d_space_contact_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ void Box2DSpaceContactListener::handle_static_constant_linear_velocity(b2Body *b
}

void Box2DSpaceContactListener::handle_one_way_direction(b2Vec2 one_way_collision_direction_A, b2Body *b2_body_A, b2Body *b2_body_B, b2Contact *contact) {
if (!world_manifold_computed) {
contact->GetWorldManifold(&worldManifold);
world_manifold_computed = true;
}
//if (!world_manifold_computed) {
//contact->GetWorldManifold(&worldManifold);
//world_manifold_computed = true;
//}
b2Vec2 normal = b2Mul(b2_body_A->GetTransform().q, one_way_collision_direction_A);
b2Vec2 vel = b2_body_B->GetLinearVelocity();
vel.Normalize();
if (b2Dot(vel, normal) > 0.9f) {
b2Vec2 body_A_velocity = b2_body_A->GetLinearVelocity();
b2Vec2 body_B_velocity = b2_body_B->GetLinearVelocity();
b2Vec2 body_A_position = b2_body_A->GetPosition();
b2Vec2 body_B_position = b2_body_B->GetPosition();
b2Vec2 relative_position = body_B_position - body_A_position;
b2Vec2 local_normal = contact->GetManifold()->localNormal;
// relative velocity
body_B_velocity -= body_A_velocity;
body_B_velocity.Normalize();
float dot_product = b2Dot(body_B_velocity, normal);
float passThroughThreshold = -b2_epsilon * 10;
if (dot_product >= passThroughThreshold) {
contact->SetEnabled(false);
return;
}
Expand Down

0 comments on commit 760f5b5

Please sign in to comment.