Door dont open ;(

Make sure to paste your scripts with proper formatting


Your current script is getting self in a round about slow way, the comment here suggests you should fill it with a different path,

    item = get_node(".") # Specify the correct path to the cube

but I would recommend using @export instead. With @export you must select the node from the inspector, this variable will appear as a property like any other.

extends Node2D

@export var Item: Node2D

Except you only want a signal from this item yes? Does your box have a signal “cube_full_on_button”? If so you can connect it through the editor in the “Node” tab next to the “Inspector”, if you do not have that signal then you will need to make it.

Then you can connect the signal “cube_full_on_button” directly to your open_door function on this Node.

But so much of this script has been wrong, I’m willing to bet it’s been a misleading starting point.

Bonus ChatGPT cringe, please never code with this program:

  1. item is in class body though only used locally in _ready()
  2. func not funk _ready()
  3. Old 3.x connection as KingGD pointed out
  4. uneccesary intermediate function _on_cube_fell_on_button()
  5. is open_door() syntax error, remove is
  6. position.y -= 100 actually moves the self node up in 2D

All together I think you would be better off with a new script, an Area2D, and connecting to it’s body_entered signal

extends Area2D

@export var door: Node2D
func _on_body_entered(body: Node2D) -> void:
    if body.name == "Box":
        door.position.y += 100
3 Likes