0 votes

hi, i am new to pragramming and godot..
I am trying to change scenes with Area2D node but only when "ui_accept" pressed

I followed this tutorial " https://www.youtube.com/watch?v=P6-fWbua6w0&index=17&list=PLTUoLxm6vZ9YlRe-oPHNH4gF00mR2OKgA "
extends Area2D func _on_Node2D_body_enter( body ): if (Input.is_action_pressed("ui_accept")): get_tree().get_root().get_node("World").queue_free() get_tree().get_root().add_child(load(SceneToMove).instance()) but only working once and when player entering.

i want it to work when my player is in the body not when entering.. please help me.

in Engine by (28 points)

1 Answer

0 votes
Best answer

Here is the answer for my question

extends Area2D

export var SceneToMove = ""
var inside = false
var action = false


func _ready():
    set_fixed_process(true)


func _on_Node2D_body_enter( body ):
    inside = true


func _on_Node2D_body_exit( body ):
    inside = false


func _fixed_process(delta):
    if Input.is_action_pressed("ui_accept"):
        action = true
        if (action and inside):
            get_tree().get_root().get_node("World").queue_free()
            get_tree().get_root().add_child(load(SceneToMove).instance())
            action = false
by (28 points)

You can use _input_event and get_overlapping_bodies/areas too, but not sure if detection will be "instantaneous" as the way you are doing it.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.