How do I stop my player from moving during an animation, and even make the animation play with this code

Godot Version

v3.5.1.stable.official

Question

What do I do to make my character not be able to move during spawn animation, and to even make the spawn animation play? I know that the idle script interferes with the spawn animation being able to play, but I’m new to coding and got the movement code from a tutorial. The move ability timer thing is the length of the animation because what im going for, is whenever the character spawns, an animation of them spawning plays, and then they will be able to move.

edit: I just noticed you’re using Godot 3, so I’m not sure the syntax I used works for everything…

You could do something like:

func _ready():
	spawn()

func spawn():
	set_physics_process(false)
	$AnimationPlayer.animation_finished.connect(_spawned_in)
	$AnimationPlayer.play("Spawn")

func _spawned_in(_anim):
	set_physics_process(true)
	$AnimationPlayer.animation_finished.disconnect(_spawned_in)

Calling the spawn() function will play the animation and disable the _physics_process() function so it won’t interfere.
Then when the spawn animation is done playing the animation_finished signal calls the _spawned_in() function that’ll start _physics_process().

Everything in _physics_process() can stay the same. And make sure the Spawn animation is not set to loop, otherwise the finished signal won’t be emitted.

The (_spawned_in) stuff makes an error for my code for some reason. I never realized how far behind I was from updates, so im gonna get godot 4.

Just a correction about the @Monday code, in godot 3 the way you connect sigals is different

func _ready():
	spawn()

func spawn():
	set_physics_process(false)
	$AnimationPlayer.connect("animation_finished", self, "_spawned_in")
	$AnimationPlayer.play("Spawn")

func _spawned_in():
	set_physics_process(true)
	$AnimationPlayer.disconnect("animation_finished", self, "_spawned_in")



Also, to avoid create another function, you can do too:

func _ready():
	spawn()

func spawn():
    set_physics_process(false)
    $AnimationPlayer.play("Spawn")
    yield($AnimationPlayer, "animation_finished")
    set_physics_process(true)
1 Like