Problem interacting with area2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stubbsy345
:warning: Old Version Published before Godot 3 was released.

So I have a 2d RPG game I am working on. I have a door animation when the player interacts with the door. The player can then walk through the door, which then shuts behind them. However, when I come back to the door the other way it isn’t allowing me to interact with the door. I am using area2d on both the character and door to interact. I have two collision shapes within the area2d for the door, one at either side of the door, the one infront of the door works but the one on the far side doesn’t.

Below is my script:

func _process(delta):
	var playerPos = get_node("playerNode/Player").get_pos()
	if playerPos.y <=  264:
		for door in Doors:
			door.set_z(1)
		for door in doorShut: 
			if doorShut[door] == false:
				get_node("Doors/" + door).set_frame(0)
				get_node("Doors/" + door + "/StaticBody2D").set_layer_mask(old_layer_mask)
				get_node("Doors/" + door + "/StaticBody2D").set_collision_mask(old_collision_mask)
				doorShut[door] == true
	else:
		for door in Doors:
			door.set_z(0)

func _open_theatre_door(door):
	var currentDoor = get_node("Doors/" + door)
	currentDoor.set_frame(1)
	old_layer_mask = currentDoor.get_node("StaticBody2D").get_layer_mask()
	old_collision_mask = currentDoor.get_node("StaticBody2D").get_collision_mask()
	currentDoor.get_node("StaticBody2D").set_layer_mask(0)
	currentDoor.get_node("StaticBody2D").set_collision_mask(0)
	doorShut[door] = false

the _open_theatre_door function is called when spacebar is pressed when the player is inside the area2d. If I go back round the bottom area always works, but the top never does, even if I try that interaction first.

Did you make sure the collision masks are properly restored as you expect when crossing the door again?

Zylann | 2017-04-25 18:20

Yeah and the collision mask are only changed for the static body to allow the character to move through, so this shouldn’t affect the area2d right?

stubbsy345 | 2017-04-26 10:42