-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Shape2D.collide_and_get_contacts returns incorrect contact points between convex polygon and line segment #48520
Comments
This seems like the expected behavior. Contact points are not necessarily along the segment shape and are different from an intersection. They are used by the physics engine for collision and they are calculated to be at the closest edge, so the shapes are pushed out from each other with minimal distance.
That said, I would like to know if there's a specific reason for you to expect contact points to be different. If something is not working as expected, could you share a bit more about your use case to see if I or someone else can help? |
@pouleyKetchoupp Intuitively, as a godot novice, I would have thought that the contact points returned by
Maybe it's just me, but it seems like the behavior in my example above doesn't align with the documentation as stated. Maybe the documentation should be more clear on this? As for what I'm trying to accomplish, I'm trying to implement a laser light in 2D, so when something collides with the laser light rectangle, the light needs to be redrawn based on the colliding shape. If |
Yeah, definitely. The documentation should explain contact points more in details and possibly link to
I can confirm intersections from the That also makes me think it could be useful to have an API in the future that helps with getting shape intersections, without having to pick specific functions manually from |
Can a method be added to find what a typical user is expecting out of collide_and_get_contacts? Actual intersection points? I don't see a single method in the Geometry class that takes 2 Shape2D objects and returns intersection points. It looks like trying to emulate our expected behavior of collide_and_get_contacts with the Geometry class in a general use case is going to take a ton of code. |
Just to be clear, the physics system is designed to provide contact points that can be used for shape separation, not generic shape intersection, so it's not a trivial thing to add to the API. The documentation for That said, if there's something commonly needed and missing in the API, we can discuss how to solve the problem. I would suggest to open a proposal (https://github.com/godotengine/godot-proposals) with more details about your use case. Then we can make an assessment:
|
Godot version:
v3.2.3.stable.official
OS/device including version:
Windows 10, OpenGL ES 3.0 Renderer: GeForce GTX 1070/PCIe/SSE2
Issue description:
Shape2D.collide_and_get_contacts
can sometimes return incorrect contact points between a convex polygon and a line segment. The following script and screenshot illustrate this:The white circles are the contact points returned by the call to
Shape2D.collide_and_get_contacts
(one of which is plainly incorrect), and the red circle is the intersection point found byGeometry.segment_intersects_segment_2d
(which is plainly correct).Steps to reproduce:
Attach the above script to a Node2D and run the scene.
Minimal reproduction project:
The above script is a sufficient test and has no dependencies.
The text was updated successfully, but these errors were encountered: