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

Add a PolylineShape2D resource for 2D collision detection #10581

Open
vbettaque opened this issue Aug 28, 2024 · 3 comments
Open

Add a PolylineShape2D resource for 2D collision detection #10581

vbettaque opened this issue Aug 28, 2024 · 3 comments

Comments

@vbettaque
Copy link

Describe the project you are working on

A Pokemon Ranger-like game where the player leaves a trail behind to encircle enemies. The trail is destroyed/damaged if enemies collide with it.

Describe the problem or limitation you are having in your project

It is not straightforward to detect collision with a polyline composed of multiple (possibly intersecting) line segments. There are multiple options, which all fall short in some regard:

  • Each segment of the polyline can be given collision individually using SegmentShape2D. However for the aforementioned project this might require adding/removing/keeping track of a large number of different CollisionShape2D nodes during each physics step, which is unreasonable and inefficient.

  • One could use offset_polyline. However this is also cumbersome to use if the polyline has intersections, and also might fail on occasion.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I propose to add a new subresource of Shape2D which represents a single polyline and would therefore be able to resolve the aforementioned problems in an elegant way. Such a resource is also present in other engines, e.g. Rapier.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

PolylineShape2D would be very similar to SegmentShape2D, but would accept a PackedVector2Array instead of just two points. The required physics/collision detection is also straightforward to implement due to the the polyline being composed of individual segments, for which these routines already exist in the engine.

If this enhancement will not be used often, can it be worked around with a few lines of script?

As mentioned before, it is technically possible to work around these limitations, but not in a few lines of script and not efficiently.

Is there a reason why this should be core and not an add-on in the asset library?

It is not possible to extend physics engine behavior through an external add-on.

@AThousandShips
Copy link
Member

This would just be ConcavePolygonShape2D but not closed, as that shape has no interior but only checks against the segments

@vbettaque
Copy link
Author

vbettaque commented Aug 28, 2024

Precisely. I was considering proposing the addition of a flag to have ConcavePolygonShape2D be non-closed as an alternative, but it would not be a polygon anymore so I didn't find it fitting.

@vbettaque
Copy link
Author

vbettaque commented Aug 28, 2024

Okay after reading more about it, I guess ConcavePolygonShape2d does look like what I want (except that its individual segments do not necessarily have to be connected it seems?). But I'd argue that the name is a misnomer then, which is why I didn't find it earlier. Also Godot give you a warning if you try to use ConcavePolygonShape2d outside CollisionPolygon2D (this is not mentioned in the documentation), so clearly the direct usage is not encouraged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants