I have a player with a flashlight. When the player goes inside a place underground, I want to hide the upper world and reset the collision and light masks. I could set the underground to a new scene, but then the enemies from the previous layers will stop chasing it. Right now, the underground part shows the underground world when you're above ground, and doesn't light up when you go into the tunnels, despite the caves having both masks for the underground world and the upper world.

Currently, I'm only trying to set the player to go underground and am working on caves.


func _on_CaveTrigger_body_entered(body):
	if body.is_in_group("Player"):
		get_node("Sky").visible = false
		get_node("Land").visible = false
		get_node("Player").set_collision_mask_bit(1, false)
		get_node("Player").set_collision_mask_bit(2, true)
		get_node("TileMap_Caves/CaveDarkness").visible = true


func _on_CaveTrigger_body_exited(body):
	if body.is_in_group("Player"):
		get_node("Sky").visible = true
		get_node("Land").visible = true
		get_node("Player").set_collision_mask_bit(1, true)
		get_node("Player").set_collision_mask_bit(2, false)
		get_node("TileMap_Caves/CaveDarkness").visible = false

What are the collision layers for Player and the cave?

The rule is: If object A has collision layer LayerA and collision mask MaskA, and object B has layer LayerB and mask MaskB, then A and B can collide if LayerA & MaskB != 0 or LayerB & MaskA != 0, where & is the bitwise-and operator.

Personally, I find it simpler to set the property collision_layer to a power of 2, and the property collision_mask to a sum of powers of 2, rather than setting individual bits.

Okay. I am still a little new to the collision masks and layers, though, I've never really had to deal with them before.

I currently have the player, lights, enemies, the ground, and the sunlight on layer 1. The underground layer is supposed to be 2, but while testing, I also have the layer and mask set to 1 and 2. I simply need to make sure the game will transition correctly under certain circumstances. The darkness of the underground layer, which is a canvas modular like the sun, is on layer 2.

I think the collision masks are actually working, it's the light masks that I have to access yet. I'll try to find how to get the light maks to change them in code.

6 months later