Hello everyone,
Today I noticed my hidden easter-egg (a door with a funny popup upon interaction) could be interacted with anywhere in the scene. This isn’t supposed to happen, since an Area2D I put as a child of the door (StaticBody2D) with a script attached should’ve only let the popup show if the player is inside the Area2D. I checked the sizing of the Area2D, it’s parents and siblings but everything looked normal. Then I checked the player. Also perfectly normal. I am also sure there is nothing else controlling my interaction in the scene.
I have noticed, however, if I go up to the door and interact with how it should be normally done and try it again outside of the door, it does not trigger and functions as intended.
I suppose the first few things I would do is:
Put a print statement in both the body entered and body exited functions to see when and how they trigger.
Maybe print the state of player_inside every frame or so as well.
The only thing I can think of is maybe you accidentally put another object in the “player” group which is in the same position as the door when your game starts.
I wouldn’t even use a group for this, I would instead check the player based on their class. I assume your player has their own script, such as “player” with a class_name set? Just check for that, instead of checking for the group.
body_entered.connect(func(b):
if b is Player:
player_inside = true
print("player entered zone")
)
and here:
func _process(_delta: float) -> void:
if player_inside:
print("player is inside in process")
if player_inside and Input.is_action_just_pressed("interact"):
print("interacted")
Ah, that door is for something unrelated (switching scenes). FakeDoor is the one I have a problem with. I do not have a CollisionShape attached to it, though.
I noticed that your Area2D for that door is inside a staticbody2D, that might cause issues. Could you try and move it outside of the staticbody2D and see if that changes anything?