Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BoxColliderShape by creating Box2D shape when is2D #1708

Merged
merged 3 commits into from
Jul 8, 2023

Conversation

Jklawreszuk
Copy link
Collaborator

PR Details

Description

This PR fixes incorrect BoxCollider detection when the is2D checkbox is selected, simply by creating a 2D BoxShape version.

Related Issue

#1707

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Jklawreszuk Jklawreszuk changed the title Fix BoxColliderShape by creating Box2D shape Fix BoxColliderShape by creating Box2D shape when is2D Jul 5, 2023
@Eideren
Copy link
Collaborator

Eideren commented Jul 5, 2023

So, looks like convex shapes are broken then ?

@Jklawreszuk
Copy link
Collaborator Author

Jklawreszuk commented Jul 5, 2023

@Eideren I don't think so, but since Bullet's documentation is poor, I can only speculate why it is wrong only for the Box shape.
Let me outline my reasoning process:
In our engine, Convex2DShape is instantiated only with the following shapes: Box (rectangle in 2D), Sphere (circle in 2D) and Capsule (rectangle + 2 circles? - 2D). Let's try to analyze each shape in turn from a mathematical perspective:

  1. rectangle - A rectangle in the 2D world is not convex. A rectangle does not meet the criteria for convexity, because if we take two points on its boundary (e.g. two adjacent corners), the line segment connecting them will pass outside the rectangle.
  2. circle - a circle in the 2D world is convex. For any two points inside the circle, the line segment connecting them will always lie entirely inside the circle. This property is true for any pair of points chosen inside the circle, making it a convex shape.
  3. "Flat" capsule (rectangle with two circles): If the ends of the capsule are convex curves (e.g., semicircles) and the body connecting them is a straight line segment, then the shape of the capsule can be considered convex. Our capsule meets these criteria and so it is also convex.

TDLR: I think because the rectangle is not convex, so putting BoxShape as an argument is not correct / does not make sense.
Also, the collision bug occurs only on the box with is2D prop, so maybe this is the reason.

Nope, like BoxShape, Box2DShape is also PolyhedralConvexShape, so maybe Convex2DShape class is broken

@Eideren Eideren merged commit 9d6d379 into stride3d:master Jul 8, 2023
@Eideren
Copy link
Collaborator

Eideren commented Jul 8, 2023

Thanks :)

@Jklawreszuk Jklawreszuk deleted the BoxColliderFix branch July 8, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants