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

Commit

Permalink
fix collide function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Dec 8, 2023
1 parent 458f110 commit 953f056
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/box2d-wrapper/box2d_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,12 @@ ShapeCollideResult box2d::shape_collide(const b2Vec2 motion1,
continue;
}
ShapeCollideResult result;
result.collided = is_toi_intersected(toi_output);
result.witness1 = transformA.p + toi_output.t * motion1;
result.witness2 = transformB.p + toi_output.t * motion2;
result.collided = true;
transformA.p = transformA.p + toi_output.t * motion1;
transformB.p = transformB.p + toi_output.t * motion2;
b2DistanceOutput distance_output = _call_b2_distance(transformA, shape_info1.handle.handles[i], 0, transformB, shape_info2.handle.handles[j], 0);
result.witness1 = distance_output.pointA;
result.witness2 = distance_output.pointB;
return result;
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/servers/box2d_physics_server_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,19 @@ bool Box2DPhysicsServer2D::_shape_collide(const RID &p_shape_A, const Transform2
box2d::QueryExcludedInfo query_excluded_info = box2d::default_query_excluded_info();

int array_idx = 0;
box2d::ShapeCollideResult result = box2d::shape_collide(box2d_A_motion, shape_A_info, box2d_A_motion, shape_A_info);
box2d::ShapeCollideResult result = box2d::shape_collide(box2d_A_motion, shape_A_info, box2d_B_motion, shape_B_info);
if (!result.collided) {
return false;
}
(*p_result_count)++;
if (p_result_max > 0) {
results_out[array_idx++] = Vector2(result.witness1.x, result.witness1.y);
}
if (p_result_max > 1) {
results_out[array_idx++] = Vector2(result.witness2.x, result.witness2.y);
}

results_out[array_idx++] = Vector2(result.witness1.x, result.witness1.y);
results_out[array_idx++] = Vector2(result.witness2.x, result.witness2.y);

return array_idx > 0;
return true;
}

RID Box2DPhysicsServer2D::_space_create() {
Expand Down

0 comments on commit 953f056

Please sign in to comment.