0 votes

I would like that when the player got close to the door and pressed a button, it would play an animation and it would change scene

func process(delta): if input.isactionpressed("uiaccept"): gettree().changescene("res://path/to/scene.tscn")

Godot version 3.4
in Engine by (21 points)

You could do that with a Tween. In your process function instead of immediately calling the change scene function you could call an intermediary function.. something like animate scene change:

func AnimateSceneChange(pathToScene: String) -> void:
    'Tween code here...

I notice you're using 3.4, if you're willing to upgrade to 3.5 you'll get access to the new SceneTreeTween class which I personally think is a much better and more logical implementation. See the docs here. https://docs.godotengine.org/en/stable/classes/class_scenetreetween.html

But if you prefer to stick with 3.4, you can easily connect the Tween All Completed signal to another function which would finally call the Change Scene function. Hope this makes sense.

1 Answer

0 votes
Best answer

I actually am working on a project where I've done exactly what you're doing (almost: a door animation in my case before the scene changes). You can easily achieve this with a signal from your AnimatedSprite (or whatever). Let's say you have a door animation called "open" and one for "shut." Then just have some logic check which animation it is and then change the scene when the animation ends. NOTE: if you are going to be copying/instancing this node, make sure to connect the signal before saving the scene so you don't have to reconnect constantly every instance.
Example:

func _on_Animated_Sprite_animation_finished(anim_name):
    if anim.name == "open":
       get_tree().change_scene(your_scene_here)
by (536 points)
selected by
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.