Open marsmoon opened 6 years ago
Seems like ConcavePolygonShape2DSW
requires the data passed in to have an even amount of points. len % 2
is true for odd numbers.
You can only add segments to ConcavePolygonShape2D, not points, so they need to be pairs of points to define the segments.
Thanks for the answer, but why can't it create a segment from for example 3 points?
Well, 3 points might not be in the same line, if you need it you can add the middle point twice (and if they are in the same line, you don't need the middle point anyway).
Internally it stores everything in a contiguous array of points and it assumes it contains pair of points to define segments. This is done for performance reasons.
Internally it stores everything in a contiguous array of points and it assumes it contains pair of points to define segments. This is done for performance reasons.
I think the performance impact is negligible, at least in terms of that the collisions against concave shapes are slower already compared to using convex shapes (for rigid bodies at least). I mean, isn't it possible to use segments internally, defining a polygon via points is more intuitive in contrast to segments. Also, it may be difficult to edit concave shapes in the editor in the future (if not using CollisionPolygon2D
): #21394. I prefer correctness over performance in this case.
commit hash: 8684b631182dffebba27bdf538129818321d0d7d
I'm getting a lot of those errors when dynamically changing the array of segments in ConcavePolygonShape2D (adding points). Collisions on some of the segments don't work. Errors are from
servers/physics_2d/shape_2d_sw.cpp:910
.What does this error mean?