0 votes

So I'm building a platformer game, for an independent study. The game's almost done. The main issue that's left is turning off player control during the death and victory animations. As it currently stands, I have this code set up that releases the buttons, but can easily be overrided by pressing the buttons again:

func _on_goal():
Input.action_release("left")
Input.action_release("right")

Is there a work-around that will permanently disable player control during the animations?

Godot version 3.4.3
in Engine by (14 points)

2 Answers

0 votes

I solved this problem by calling queue_free() on the player when they die, but it depends on your set-up (if the camera is a child of the player, it will disappear too; death animations might not play if they're children of the player, etc).

You can disable input with set_process_input(false), so one way to do it might be:

func die():  
     set_process_input(false)
     yield(get_tree().create_timer(1.0), "timeout")
     queue_free()

The timer you create with yield(get_tree().create_timer(1.0), "timeout") would give you space to play the animation (make it as long as the animation), and then you can remove the player from the scene.

Hope this helps!

by (166 points)

I tried putting in the set_process_input(false)portion on my character for both when the character dies in the game or beats the level. It still doesn't work. And as an added problem, because you can still move the character, you get hit by an enemy even as you're dying. So I had to write extra code to stop the character's health from dropping below zero. My character does have a finite state machine that controls it's movements. Could that be interfering with the command to turn off player input?

Not sure - definitely try playing around with that, see if disabling the finite state machine and handling motion another way makes a difference.

You can also try set_block_signals(true) instead of set_process_input(false) - might have the desired effect.

0 votes

Just check whether the player is alive or while doing an animation dance before the movement, for example:

var is_alive = true
var is_dancing = false

if is_alive == true and is_dancing == false:
    # movement....
by (18 points)
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.