-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add Shape2D::collide_and_get_intersections()
#3563
Comments
Shape2D::collide_and_get_intersections()
It appears to me that That said, perhaps this is something to be exposed/implemented via Goost in Of course, it would be much more efficient to have dedicated function for each type of shape intersection. For instance, see the table at Object/Object intersection page (both static and dynamic intersections). To note, dynamic intersections (with motion) are not easy to generalize according to my research, but this is probably something that will be considered too corner case to be exposed in Godot anyways. |
Nevertheless, everyone creates either |
I agree, I think there's no need to introduce potential cyclic dependency between But something tells me that Godot does not have those routines implemented due to SAT algorithm I mentioned. So it's a question of whether Godot would be willing to implement and maintain those new collision detection methods in core. Hopefully @pouleyKetchoupp could work on this! I'm actually fairly interested in this subject myself, that's why I created |
In my view, Shape2D is the most basic shape class, and thus would be a good class to use for the detection of intersections. There is already a CollisionShape2D node which is more specific purpose, and from its name, Shape2D seems like a very basic shape class. If it is really intended just for physics calculations, then it should be named as such (like CollisionShape2D is). I thought the collide_* functions were simply included in the Shape2D class mostly for convenience, rather than having them in a separate physics-specific singleton. I think it would be good to either add an interdect_with(Shape2D) function to Shape2D, or perhaps a Geometry.intersect_shapes(Shape2D, Shape2D) method, to keep all geometry functions together. These would need to include transforms for the shapes too. Alternatively, perhaps we could have a GeometryShape2D class similar to CollisionShape2D, which would contain the transform and Shape2D, and provide an intersect_with(GeometryShape2D) function. This definitely needs more discussion, but I like the idea of having a GeometryShape2D class. Perhaps I should create a separate request for adding that specifically? |
Describe the project you are working on
Action platformer that makes ample use of hit box collision. Need to know how exactly hit boxes and hurt boxes collide for various scenarios such as adding hit effects at the correct position. The hit/hurt boxes are Area2D nodes, and the shapes inside the hit/hurt boxes can be any Shape2D sub-class.
Describe the problem or limitation you are having in your project
I was expecting Shape2D::collide_and_get_contacts() to give me the yellow dots in this picture. Apparently it does not, and isn't designed to do so.
There doesn't appear to be a built-in method for obtaining all intersection points between two arbitrary Shape2D.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a new method Shape2D::collide_and_get_intersections() that takes the same arguments as Shape2D::collide_and_get_contacts(), but returns all intersection points instead.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
This is basic intersection detection. Many methods in the Geometry class help with this, but for a general use case there's a lot of work to be done for detecting intersections between any two arbitrary Shape2D.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, this is a prohibitively long solution due to all of the different types of shapes that can interact. A simplified, inefficient solution such as converting all shapes to a common format first (like PoolVector2Array of segments), then detecting intersections based on segments may be sufficient for many games where Shape2D::collide_and_get_intersections() is only used once on a contact frame, but even this simplified solution couldn't support Line2D without some sort of hack like just making the segment extremely long.
A limited example:
Is there a reason why this should be core and not an add-on in the asset library?
I don't see why the engine that already detects shape intersection internally wouldn't be able to expose this functionality.
The text was updated successfully, but these errors were encountered: