Tilemap Z order bug?

I have a simple main collection that contains a player.go and a house.collection as bellow.

The player.go has a zorder of 0.5 and tilemaps go has a script that on_init changes the zorder of #walls to 0.6 but for some reason the #floor tilemap also shows over the player.

Is my script wrong and for some reason it changes the zorder of the whole go or is this a bug?

Also if I change the zorder of #walls in the editor, lets sat to “1”, when i pprint(line 9) it gives me a vector3(0,0,0) .

Thanks!

You can’t change the transform (position, rotation and scale) of components at runtime.

This means that your call to go.set_position("#walls") will modify the position of the game object to which the “walls” component belongs.

1 Like

Oh, thanks! So basically if I want this sort of functionality I should use multiple game objects right?

1 Like

Correct!

1 Like

Ok, thank you!

May I ask why you’re not using the same tilemap for both floor and walls?
The layers in the tilemap have different z values.

They use different tilesources for performance reasons, noticed that the editor is really slow when editing a really big tilesource.
Like, when adding a tile to a collision group it takes 5+ seconds and it freezes my PC( using PopOS 20.10 with a Ryzen 3700x and 32GB RAM with a 2000x6000ish tilesource png). I also tested it with a half size tilesource 1000x3000 and it still takes 2 seconds.

1 Like

Thanks for the info. Sounds like something for @mats.gisselson to look into.

Also, if I could add, there is currently nothing in the API reference or manual on how to get the Z of a tilemap layer, I tried with get_position and get_world_position on “/house/tilemaps#walls/walls” (tilemap “walls” has a single layer called “walls”) but I always get 0,0,0 even when I change it in the editor. Any ideas?

I know I probably miss something but can’t find any info on this.

Correct, you cannot get the z value of a layer.

Well in that case, and assuming what brizl said about setting the position of a tilemap layer just changes the parents go position also applies to tilemap layers, seems like for my use case my only option is to use multiple go, each with it’s own tilemap so I can change their z order programmatically.

Thanks for the help, I really appreciate it!

1 Like

Do you need to get the z layer of the layer? You already know it from the editor?
E.g. in the script you can use your own variable for it, using the same value from the editor:

local LAYER_Z_WALL=0.5

Then the actual Z is the Z of the owning game object + the layer z.

I guess another way is to move the objects that should go between the layers?

I’m sure you have got things covered as it is, I’m just interested in our users use cases and how they make them work for their purposes :slight_smile:

2 Likes

I basically need to do something like the picture bellow, where I want the player to be able to be in front and after a wall. Basically make the zorder of the wall bigger than the players when Y of player is bigger than Y of the base of the wall and the reverse. This is a simplified example as there are other objects on diferent layers in the scene.

“local LAYER_Z_WALL=0.5” : I don’t really like doing things this way as I think it’s prone to user error and I’m sure I’ll struggle with a bug for 2 days before I notice I forgot to change the value in the editor :smile:

EDIT: I already have this implemented in a crude way by having the house be at z 0.5, player at 0.51 and the walls set at 0.01 (so 0.51) and I toggle the walls z to 0.49 and 0.5 to make them be in the front or back of the player.

This is fine, but I will have buildings with 4+ layers of walls and I’d like to be able to programatically convert the TiledEditor json to defold go and just plug and play a script :slight_smile:

Since you mentioned the tilemap being large, I assume your “walls” tilemap contains all walls for the game?

How do you deal with the z positions of the characters if you move the walls in Z?
Do you move the wall layer once at the start, or every frame?

EDIT:
I didn’t read your last post fully, and now I understand.

I don’t see it as much different from the “currentPosition.z = 0,6” in your first post though :slight_smile:

Nope, I use a collection for each type of building as I will turn them on and off if they are not in view of the player.

For now I’m just debugging so I just use a key press, but my plan is to use collission objects for each room as I don’t think that doing this on_update is a good idea.

“How do you deal with the z positions of the characters if you move the walls in Z?” using the same collision objects(I hope :sweat_smile:)

1 Like

Yeah fair point, I didn’t knew that was the go position and not the tilemap position when i wrote the post :sweat_smile:

1 Like

The tilesource is really big, the tilemap is like 20x20/30x30 as I will have one for each building. The terrain will be on a different tilemap where I’ll try to split it in chunks and just show the chunks that are visible to the player. I’ve read on the forum that this should be a good idea.

I think I’ve got my answer though, I’ll have to test my idea but setting a different z for each layer should actually do the trick if I combine it with my collision objects.

Is there a simple way to set and add extra data on a trigger collisionobject message or I need a go with a script that handles the collisions and sends another message with the extra data that I need?

1 Like

There is no way to attach custom data to the physics messages, no.

1 Like

Hi! Just in case anyone on the future is struggling with this exact problem, I have found an elegant solution.

Cut the sprite of the wall (or other obstacle) in half along the X-axis, so you have two sprites. One should have the top half of the image, the other, the bottom half.

Add those sprites to a game object, and set the z layer of the bottom sprite to 0.49. set the top sprite to 0.51. Set the sprite of your character to 0.5.

Now, the character will be behind the top part of the wall, and in front of the bottom part.

1 Like