Layer and Mask Selections

Greetings, and thanks for the course! Enjoying it so far.

I had originally run into the same problem as Kbatchelor (thanks to his post I spotted the error with the tile map), where the spikes would trigger as soon as the level loaded. Correcting the masks (and double-checking the layer selections as well) did not solve the problem. What actually solved the problem was removing the “player” selection from the spikes’ mask. And – it worked correctly after that. This made me curious, so I explored the layers and masks. Turns out I can uncheck all masks for the spikes and the tile map, leaving just the appropriate selections in the layers checked (spikes = “enemy” and tile map = “terrain”). The player is on the “player” layer and has “enemy” and “terrain” checked off in the masks. And everything works properly.

I am wondering then why we need to check off “player” for the spikes or the tile map when, as long as the player has the proper masks, everything works properly? (and, in my case, better)

Thanks for any input here. Hopefully I was clear with my explanation :slight_smile:

Edit: So I went over this numerous times with the same result, but one last time and I was able to check the “player” mask on the spikes and I didn’t get the trigger. Either I missed something three times prior (possible, afraid to say), or Godot is a bit buggy in this regard. But my question still stands – why not just check only the player masks? Thanks.

I concur that the collision layers and masks can be very confusing, but AFAIK your proposal is right.

I might be mistaken, but this is the criteria I’m using:

  • “Collision layers”: This node/object is placed in the layers indicated here (multiple layers allowed).
  • “Collision mask”: List of the layers whose objects you’re interested in interacting with; that is, the collision callbacks will trigger if an object is in one of the “mask” layers and is colliding with this node/object.

So you only have to put the mask in the node that uses the collision callbacks or query collisions with get_colliding_bodies().

In the case that you put the mask but don’t use the collision callbacks (nor use get_colliding_bodies() ), the mask has no use and nothing happens.

Thanks!

You make it sound easy until I have too many beers – I mean, it gets too late :slight_smile: But I joke (or do i??).

Thanks for the input and confirmation. My unstated thought here was that if I don’t have to check off masks AND layers, it may greatly simply the development process as things get complex, since one would only need to track the settings in one object. Of course, no plan survives its encounter with the enemy (queue ominous music).

1 Like

This is the best explanation I have found,

Collision layer is what you are, and the mask is what you collide with, so when I make …Body2D’s I think:

“I am a layer and I can hit mask”

So in practice it sounds like:

“I’m a player, marks player check under layer, and I can hit coins, marks coin check under mask, and obstacles, marks obstacle check under mask”

found in comments for this video… which I didn’t need to watch :slight_smile:

https://www.youtube.com/watch?v=UZu8NwlkXcU

Privacy & Terms