Area2D body_entered triggering instantly upon scene load.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By droc101
func _on_Area2D8_body_entered(body):
if Input.is_action_pressed("opendoor"):

this code it triggering instantly upon scene load. I do have code to wait one frame under the _ready function. i want it to trigger only when the player (KinematicBody2D) enters the area2d. The player does not spawn on an area2d.

:bust_in_silhouette: Reply From: LoneDespair

maybe its colliding with something else

try to check if its the player it is detecting
body.get_name() == “PlayerName”

or better

try to have a dedicated collision layer for your player and change the collision mask of your detectors to that

:bust_in_silhouette: Reply From: twinpixel

I can confirm that problem. It seems to be some sort of bug in the engine.

You could try to use

yield(get_tree(), "idle_frame")

before adding the player to the scene.

Or set the initial position of the player to a very far away position, before adding it to the level and then setting it to the proper position, when entering the level.

Guess who helped me big boy! YOU!! 5 hours on this one. Guess its those chumps fault ahahahah Knew it wasnt my code… No no no

star pirate | 2021-10-23 17:23