godot icon indicating copy to clipboard operation
godot copied to clipboard

Segment based polygon shapes only get collisions on edges

Open eon-s opened this issue 8 years ago • 14 comments

Godot version: 3 26ff90eae

Issue description: If a polygon shape is built in segment mode, the interior of the shape is empty, only the segments are valid collisions.

Steps to reproduce: Create a PolygonShape2D in segment mode.

Link to minimal example project: shapetest-bug.zip (the one in the center is in segment mode)

eon-s avatar Aug 05 '17 13:08 eon-s

Isn't there an option to decide how detection is done? Like, only segments, interior, exterior?

Zylann avatar Aug 05 '17 15:08 Zylann

I don't see anything like that on the shape properties, just build mode (solids or segment), polygon(Vector2), disabled and one way options.

eon-s avatar Aug 05 '17 16:08 eon-s

PolygonShape needs to work around the issue that the polygon may be concave, while the SAT collision detection supports only convex shapes. For this purpose, there are two build modes:

  • Solids uses convex decomposition to split the concave polygon into multiple convex polygons
  • Segments constructs the polygon's outline out of line segments, as a consequence the shape collides only on its circumference

So the behavior you're observing is intended with Build Mode set to Segments

leonkrause avatar Aug 06 '17 12:08 leonkrause

you can't use a polygon as rigidbody if you set it to segments, should work fine as static though. this is not a bug. This is why the default is Solids and not segments for it.

reduz avatar Aug 06 '17 12:08 reduz

maybe we should add a warning sign to the shape if we detect the parent is a RigidBody

reduz avatar Aug 06 '17 12:08 reduz

reopen to remind us to add such warning sign

reduz avatar Aug 06 '17 12:08 reduz

@eska014 I see, but a body should collide with the internal part/side of the shape?

@reduz the example uses a static body with segments, just to test how a regular rigid can get stuck inside the shape and intersect_ methods can't hit it.

eon-s avatar Aug 06 '17 13:08 eon-s

Using raycast2d, I get the same problem as @eon-s - gets stuck inside the tile

blurymind avatar Nov 26 '17 19:11 blurymind

@eska014 I see, but a body should collide with the internal part/side of the shape?

yes, segment shapes are like a 0 tick wall, this works for both keeping bodies outside and also inside of the sahpe, it's a feature, not a bug. if you need to be able to exit, but not enter then consider using one_way_collision

Using raycast2d, I get the same problem as @eon-s - gets stuck inside the tile

i have comented in your issue, your case is different, related yo execution order (you are changing raycast direction and checking collision on the same frame, this causes a fake negative)

MarianoGnu avatar Nov 26 '17 19:11 MarianoGnu

@MarianoGnu I will give it a try and make a minimal example

blurymind avatar Nov 26 '17 21:11 blurymind

@MarianoGnu one way collisions have problems with raycasts too (are not one side for them) #9423

None of these collision issues are tagged for 3 so I guess some will not be fixed for next stable.

eon-s avatar Nov 27 '17 03:11 eon-s

We have now entered release freeze for Godot 3.0 and want to focus only on release critical issues for that milestone. Therefore, we're moving this issue to the 3.1 milestone, though a fix may be made available for a 3.0.x maintenance release after it has been tested in the master branch during 3.1 development. If you consider that this issue is critical enough to warrant blocking the 3.0 release until fixed, please comment so that we can assess it more in-depth.

akien-mga avatar Jan 09 '18 16:01 akien-mga

If bodies with segments-based shapes are meant to be taken as "non-solid" or "empty" bodies, then this just need proper documentation.

eon-s avatar Apr 06 '19 18:04 eon-s

Behavior remains the same on 4 with the new body types, maybe is a good time to add these details to the rework on physics documentation or CollisionPolygon2D definition.

I don't know if this should be opened on the documentation repository instead.

eon-s avatar Aug 16 '21 20:08 eon-s