PolygonCollider2D - Can I draw straight lines?

So hey. I’m quite new to Unity and to game development in general and I’m currently creating a Tetris-like game. During the creation I stumbled upon a problem concerning the Polygon Collider 2D. Since some Tetris pieces are in an irregular shape I have to use the Polygon Collider, but the problem with that is that it’s not that accurate. For example I’d like to draw a straight line from point A to point B, but dragging those lines with a mouse don’t really give me straight lines and 90 degree angles. Although I can get it close to perfect, it’s still not perfect and while playing the game there are always pieces that don’t fit perfectly. I also can’t set the coordinates manually since the points coordinates are all grayed out under inspector.

So… My question is, is it possible to get straight lines and 90 degree corners with the polygon collider? Maybe I’m missing a key or shortcut or anything (like with photoshop you can hold down shift key to get straight lines).

As I understand it’s possible by using code, something like this?

polygonCollider.pathCount = 1;
polygonCollider.SetPath(0, pointsArray);

But to be honest it would be a lot easier to do that in the Unity window.

Thanks.

I would suggest not using a physics engine for Tetris at all.
Tetris uses discreet coordinates for blocks and a physics engine would just introduce errors.

See http://noobtuts.com/unity/2d-tetris-game (
https://www.youtube.com/watch?v=UZSotPFf0ug
) for a good example.

As for your question - no I don’t think there is a way to snap lines in the polygon editor to specific angles.

Well, like I said it’s a Tetris-like, not really a Tetris. Preview can be seen here about what I’m talking about: www.alkocen.com/tetris, so there is physics involved.

If I would create real Tetris then yes, I wouldn’t use physics, I would just “teleport” the pieces over a specific interval.

But too bad, it would be a useful tool to have. Anyway, thanks for the answer :slight_smile:

Cool demo. I see what you’re doing now!

Anyway the great thing is that you can extend the editor and make your own PolygonCollider2D editor :slight_smile:

Ah, good to know! I’ll look into it :slight_smile:

Might be a bit late but I encountered a similar problem while making a blocky sort of thing.

I posted my custom editor here:

1 Like