Unity-Technologies / 2d-extras

Fun 2D Stuff that we'd like to share!
Other
1.54k stars 342 forks source link

Composite Collider 2D No Longer Generating 'Straight' Lines Between Points in 2019.2.11 #151

Open TomMetaG opened 4 years ago

TomMetaG commented 4 years ago

After updating from 2018.3.12 to 2019.2.11 the Composite Collider 2D, when used with the Tilemap Collider, no longer generates straight lines between points, breaking collisions in our project. This may be caused by the current inability to set an offset distance of 0. See in the image below, where it's generating extreme float values for the highlight positions.

CompositeCollider2DIssue
ChuanXin-Unity commented 4 years ago

Sorry about this. We will update Offset Distance such that you can have the behavior from 2018.3 by setting offset distance to 0.

Out of curiosity, would you mind sharing with us why you would like to have exact vertex positions for the colliders? Thanks!

TomMetaG commented 4 years ago

Excellent, thank you!

Sure, for our 2D game, we use a raycasting system for player collisions. For certain behaviors, we assume exact vertex positions (i.e. precise and predictable horizontal, vertical, and diagonal lines) and allow certain actions based on ray hit distance, from multiple rays fired from the character. Wall slide, for example, is automatically enabled when the middle two rays both return a hit -- the minor float differences result in these checks no longer both returning hits, and are instead detected as minor slopes (resulting in different behavior). While adding in extra float fudge to these checks could mostly work around the issue, having perfectly aligned vertex positions and exact grid alignment makes 2D game development and debugging MUCH easier (especially retro style or pixel-perfect platformers like ours with perfectly straight horizontal and vertical surfaces, and fixed tile angles).

ChuanXin-Unity commented 4 years ago

I understand, thanks!

We will update Offset Distance in CompositeCollider2D so that you can set it to 0. To get the behavior you require, you will need to set Extrusion Factor to 0 in TilemapCollider2D as well.