Sean Barton - Game Developer

Tiled2Unity: Edge Collider Support in Tiled Layers

06 July 2014

Hi there! Tiled2Unity is no longer in development nor supported. Use SuperTiled2Unity to import Tiled Map Editor maps into your Unity projects instead.

Edge Colliders for One-Way Collision

Judging from the emails I’ve been getting, my little Tiled2Unity tool is proving to be useful for developers wanting to bring their Tiled Map Editor levels into their Unity projects.

The best received feature in Tiled2Unity is the ability to build up collision geometry from the tiles you lay down — but it only supported creating a PolygonCollider2D from rectangle and polygon objects. With the release of Tiled2Unity 0.9.3.0 (download latest Tiled2Unity here), support has been extended to polylines which are represented as EdgeCollider2Ds in Unity.

EdgeCollider2D Example

The most obvious use of this feature is for the type of one-way collision that you find in so many old 2D platforming games. That’s cool but I’ve put together a different kind of example that takes the moving platforms from Mega Man 2 (yes, again with the Mega Man references) and shows how they could be implemented with help from Tiled2Unity.

Moving Platform in Mega Man 2

These platforms move along a charted path and seems like a great use for the EdgeCollider2D class in Unity — but having to draw out that path by hand would be a total pain. Instead, we’re going to add polylines to the tiles that make up that platform path and have the Tiled2Unity exporter create the EdgeCollider2D object for us. This way we could change the visuals of the path and the physical colliders would automatically update to match.

Adding Polylines To Tiles

We start off with the platform-map.tmx file in Tiled …

Mega Man2 Map in Tiled

Just like we’d add polygons and rectangles to tiles in Tiled we can add polylines using the Tile Collision Editor.

Tile Collision Editor - Adding Polylines

After adding all the polylines to all the “path” tiles we can launch Tiled2Unity and preview the results …

Edge Collider Preview in Tiled2Unity

That path gets built into one continuous EdgeCollider2D component with 44 vertices which is exactly what we wanted. The example comes with a Platform sprite which is programmed to traverse that path (see the custom PlatformCharacterController.cs script).

Tiled2Unity Map Exported to Unity With EdgeCollider2D

And we’re done. Send questions to me via the comments or email. Happy developing.

Seanba

Hi! My name is Sean Barton (aka Seanba).

I’m an American-Canadian software developer working in Austin, Texas where I never have to shovel snow. :fire:

My career focuses exclusively on video game software and tools. You can read more about me here.


Aseprite2Unity

Aseprite2Unity imports sprites and animations for use with your Unity projects. Like all my tools it is available for free or name your price.

Get Aseprite2Unity.


SuperTiled2Unity

SuperTiled2Unity is a collection of Unity scripts that import Tiled Map Editor files to your Unity projects. You can download for free or name your price.

Get SuperTiled2Unity.

(Note that regular Tiled2Unity is now deprecated.) :zzz:


Seanba

Like my tools? Consider making a donation as a way of thanks!