0 votes

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 opentheatre_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.

asked Apr 25, 2017 in Engine by stubbsy345 (284 points)
edited Apr 25, 2017 by Zylann

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

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?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.