Cammin / LDtkToUnity

Unity importer for the LDtk level editor
https://cammin.github.io/LDtkToUnity
MIT License
388 stars 39 forks source link

Collision with mirrored rules for non-square tiles #29

Closed timvancann closed 3 years ago

timvancann commented 3 years ago

I'm unsure if this is supported hence the issue. If it is supported please share how to use it in Unity.

In LDtk I have an IntLayer with a bunch of rules. There are 2 grid values: 0: solid blocks 1: 45 degree angle slopes

This allows me to paint a level including slopes. The tileset is setup in such a way that tiles are mirrored, hence rules are also setup that way. Slopes both ascending and descending are then automatically painted in using a single rule (with mirror x,y enabled) on the grid value 1.

In Unity I have to apply an LDtkIntGridTile to each of the grid values. On value 0 it's easy. A single block with a square collision shape. For grid value 1 I have a single 45 degree ascending slope with custom collision shape. But for the slopes I notice that 2 things are not working:

  1. The collision shape doesn't match the slope, but it just remains a full block.
  2. The collision shapes are not mirrored like the tiles are. That would imply I need a new grid layer, and a new LDtkIntGridTile for each mirror-version of each non-block based tile.

Is it true this is not supported, or am I missing something obvious?

How would that work with more complicated shapes? E.g 33.3 degree slopes spanning multiple tiles to reach to 1 block height?

Cammin commented 3 years ago

Hi, thanks for reaching out about this.

1. Interesting that a custom shape tile is colliding as if it was a full square. Maybe there are prefab overrides in the scene that are affecting the tiles? We can also talk about this more here if the problem is still hanging around.

2. In regards to slopes and rules, it's would not be possible to have rules dictate collision.

deepnight answered a similar question in the discord server a while back; If you wanted to have a block and a slope that can also mirror, then that would total to 3 intgrid values. One for the block and 2 for the 2 slopes one left and on right. The same logic applies for 30 degree slopes, which would add 4 extra intgrid values in this case. Each intgrid value would be considered its own unique shape.

It may be quite a bit of bloat and some extra rules work to account for the extra intgrid values for slopes, but it's the solution that I've seen deepnight recommend and so it's also the convention I personally follow as well.

Hope I've helped out, but feel free to post any more issues or ask any additional questions if needed 🙂

timvancann commented 3 years ago

Hi, thanks for repying so quickly!

  1. I checked a few things but couldn't find anything obvious (it's a fairly blank project with no prefabs). But I remembered that I duplicated the block LDtkIntGridTile and changed it to a slope. I deleted it and created a newLDtkIntGridTile, added the slope tile and the collisions worked as expected! I'm fairly certain that, as you've suggested, something may have been lingering in cache somewhere that was messed up. In any case it's resolved now. I'll keep a close eye on if I can spot any predictable behaviour!

  2. That is a clear answer. I wasn't aware that this was the prefered workaround. I'll follow that convention, thanks!

Cammin commented 3 years ago

Here's the conversation in question, take it as you wish. But I saw deepnight do this so I can trust this. But maybe it's good to re-ask the question if his opinion had changed 🙂 image
image