Seanba / SuperTiled2Unity

Imports Tiled files to Unity. Better than regular Tiled2Unity.
MIT License
666 stars 84 forks source link

simplification of polygon collider geometry #163

Open jamesrobb opened 3 years ago

jamesrobb commented 3 years ago

Hello,

My apologies as this is more of a "how do I?" question then a bug report; I'm not really sure where to ask such questions.

I'm importing a very basic map into Unity which resulted in the geometry of the polygon collider (which are the green lines) seen in the attached image. You'll notice that in the area circled in red that there is a line that is part of the geometry that doesn't quite track the actual perimeter of the tiles; this causes collision problems in-game. On the right side of the image one should notice that the geometry is also quite complicated.

I'd like to know:

As an FYI, in Tiled I have a collider on each tile that is the exact same size as the tile.

Thanks,

geometry of polygon collider as seen in the unity editor (geometry of polygon collider as seen in the unity editor)

Seanba commented 3 years ago

Hi there, @jamesrobb. Sorry for the late reply. For your questions:

  1. That extra polygon in your red circle looks like a bug. I've had issues before where I had to remove the map prefab from my scene and then add a new one back to fix such issues. This is a bug with Unity prefab instances built through custom asset importers (I've logged the issue with them some time ago). However, if the bad geometry remains after replacing the prefab instance then it is likely a bug on my end. If you send me your project I can take a look.
  2. The best/fastest way to simplify the geometry is to go into the Project Settings and opt for Outlines as the Collision Geometry Type. Note, however, that your collisions will now be outlines instead of "solid" polygons and depending on your game engine may need to be modified for that. For instance, objects that are fully "inside" a collider will not generate a collision.

image

jamesrobb commented 3 years ago

Thank you very much for the help!

  1. Setting the collision geometry type to "Outlines" definitely worked and produced the desired result :)

  2. While leaving the collision geometry type as "Polygons" re-importing fixed the issued I had described but another issue still exists. If you reference the two images below you will notice that my player sinks into the floor beneath him as the geometry erroneously slants down to the right. I'm not sure why this is. Any ideas?

Closer View

The thick yellow outline is not does denote the collision geometry, as an FYI, we are interested in the thin green lines.

Closer View

Zoomed-out View

Zoomed-out View

jamesrobb commented 3 years ago

As much as I dislike bumping I'm bumping this. Any idea what might be causing this or how I could look into it?

Seanba commented 3 years ago

Hi there, @jamesrobb. Sorry for the lack of replies. I've been having difficulty finding time during the pandemic.

It would be useful to see what the "real" collision geometry is by disabling the gizmo for the SuperColliderComponent ...

image

This will help you concentrate no the thin green lines so we can make sure the geometry looks right.

It might be good to send me a copy of your project so I can take a look. My email is sean@seanba.com.