# Questions about multiple layers and collision

Hi guys,

I’m currently working on a class project to create a 2d bomber-man-like game using Unity and I’m stuck at figuring out how to move my characters between layers while maintaining the integrity of the tiled map.

This is the 15-by-11 map I created:

And there are 14 layers in this map (11 layers for 11 rows and some other for miscs). So the order would be layer 1 is used to put on object on row 1 and so on for other layers/rows all the way down.

The concern I have right now is I don’t know which layer to use to put my character on (assuming I have a layer of collision and I will put my character in there).

Say the character is at position (3,3) - row 3 - layer 3 (assuming origin is top-left), how is it possible for the character to [stay on top of/hide objects of] row 2, but is hidden by any object from row 4?
–> If I station my character in one layer then this will not produce a desired result when my character moves from row to row.
–> If I dynamically move my character between layers then the entire scenario will become quite complicated if I add move-able monsters onto the map and apply the same method?

I’m using PopTag! as my reference right now btw.

http://nxcache.nexon.net/poptag/game/1pdemo.html

If this doesnt work out I might have to make the map completely 2D - 90 degree look down, or try with 3D and fix the camera angle to give the 2D feel.

What do you think?

Hm. I think using that many layers should not be nessecary…

Unfortunatly I do not know how exactly your character / monsters and tiles are defined… Are the boxes and stones single tiles? Are the actor sprites (characters, monsters) only one tile large or would they overlap over multiple tiles?

Generally the easiest solution would be to use single tiles for every tile which at some point can before and behind a character and then simply render everything sorted by the y-coordinate (so if the player’s y is lower than a box y it would be behind it or vice versa. The map of your screenshot should be buildable with 2 layers then… One for the ground and boxes and one for tiles which are wider than one tile (the tree).

If you further assistance you can upload your tileset(s) here and I could show how I would solve the issue.

Regards,
Erik

Absolutely. Please check the dropbox link below since I dont think Im allowed to add attachment file yet.

Yeah I also find that having so many layers unnecessary … but since I’m entirely new to tiled map editor, I was just trying to achieve the visual first, and not sure how to do so the other ways.

About the objects, since I designed everything by myself … I was trying to mimic the desired result by making the individual objects comprised of multiple tiles ( for ex: you can look at the wood block/rock block I made, it’s basically comprised of 2 tiles with transparent background)

Sitting in the train currently, without proper internet. But it looks like
you only uploaded the .tmx file. That file does not include the tileset you
used. Can you lease upload the referenced tileset files too (otherwise the
map won’t open for me).

Then I can take a look as soon I am home this evening.

Regards,
Ablu

I thought that the .tmx includes my tileset in there already. But if anything you could check out the folllwing tileset I used for my map.

Other issues I came across while playing with this is that:

• I wanted some of these objects to be destructible so I tried importing the map to unity and it’s not clear to me how to access each individual object (so that I can destroy them during runtime) as they all seem to be grouped together within each layer (for each tileset type)
• Also on the same page with the issue above, I cant seem to get the exact world location of these objects in unity, as transform.position always return zero for me regardless whichever component is being checked

The reason I’m looking at this is because I googled and some answer for the rendering order issue popped up suggesting that I should use the character y-position and compare that with the target object’s y-position to determine its rendering order in respect to the object during run time (by changing the sub-order within given sorting layer)

And also the collision issue of different objects in different layers for me seems to be resolvable using the layer-based collision. I haven’t tried it out yet, but from what I read it looks like I can set how objects from layer A can collide with objects from layer B as long as I check the box in the layer collision matrix to allow these 2 layers to collide with each other.
http://docs.unity3d.com/Manual/LayerBasedCollision.html

This is how I would do it:

https://dl.dropboxusercontent.com/u/45541625/SampleMap.zip

For rendering you only need to order by the y axis. About the collision: I do not see how splitting the map into multiple layers makes that easier. But I also have no experience with unity3d. So I fear I cannot help you with that and the other issues you mentioned in your last post.

1 Like

Thats real helpful for me in future map making. Thank you