Hello Godotians, I have a fancy death animation on my game and it seems that I can still move my character while the animation is playing, I was able to stop the character from moving but whenever I press the direction keys the dying character changes direction while exploding, is kinda amusing but also annoying.

So here's the question, is there a way to stop the character from receiving keyboard input? I need to stop the player from being able to control the character in some moments, any help will be appreciated, never stop being awesome.

One way is to make a boolean (like is_alive) and set this to false as soon as the death sequence starts. Then on your functions that move the player can make sure you check that "is_alive" is true before doing anything.

Ideally you could use a state machine (FSM) to have a variety of states with different feedback. In that case you would check that the state is "dead" (or whatever you name it).

Though if you like you can also disable the input directly:

set_process_input(false)

That will work, but it's probably better design to use a FSM.

Hi! Thanks for answering.

Well, it seems that for the life of me I was not able to solve this.

I tried putting the set_process_input(false) everywhere on my script, I tried destroying the main sprite and replacing it with the explosion, and I still got the same result whenever I moved the character. I am using an animation tree with a few blendspaces 1d since I want different animations for left and right, and so far everything was working tip top until I hit this roadblock.

Well, anyways, it seems that is time for me to show my duct taped code, not being a programmer (I am an artist by trade) and working with Godot has been an interesting experience.

I really appreciate any feedback on as to how to stop controlling the dang character when its dying, so here is my code, I hope is not that much of a hassle for you, Mr, Cybereality, or for anyone in the community to take a look at it and give me a few pointers, thanks in advance, keep being that awesome.

So here's the code:

extends KinematicBody2D

var health = 1
export (int) var speed = 1000
export (int) var jump_speed = -1000
export (int) var gravity = 2000
export (float, 0, 1.0) var friction = 0.25
export (float, 0, 1.0) var acceleration = 0.25


var velocity = Vector2.ZERO

onready var anPlay = $AnimationPlayer
onready var anTree = $AnimationTree
onready var shadow =$shadow
onready var shadowTree = $shadowTree
onready var animState = anTree.get("parameters/playback")
onready var shadowState = shadowTree.get("parameters/playback")

func set_blend_position(dir: int) -> void:
	anTree.set("parameters/idle/blend_position", dir)
	anTree.set("parameters/run/blend_position", dir)
	anTree.set("parameters/jump/blend_position", dir)
	anTree.set("parameters/jump_loop/blend_position", dir)
	anTree.set("parameters/fall/blend_position", dir)
	anTree.set("parameters/hit/blend_position", dir)


	shadowTree.set("parameters/idle_shadow/blend_position", dir)
	shadowTree.set("parameters/run_shadow/blend_position", dir)
	shadowTree.set("parameters/jump_shadow/blend_position", dir)
	shadowTree.set("parameters/fall_shadow/blend_position", dir)
	shadowTree.set("parameters/hit_shadow/blend_position" ,dir)

func _ready():
	anTree.active = true
	shadowTree.active = true

func _on_Deathzone_body_entered(body):
	yield(get_tree().create_timer(2),"timeout")
	get_tree().change_scene("res://Stage_1.tscn")
	
func bounce():
	velocity.y = jump_speed * 0.5

func damage():
	$damage_player.play("damage")
	health = health - 1

func _physics_process(delta):

	velocity.y += gravity * delta
	var snap = Vector2.DOWN * 16 if is_on_floor() else Vector2.ZERO
	velocity = move_and_slide_with_snap(velocity, snap, Vector2.UP)
	set_process_input(false)

	if Input.is_action_just_pressed("ui_up"):
		if is_on_floor():
			velocity.y = jump_speed
		
	var dir = 0

	if Input.is_action_pressed("ui_right"):
		dir += 1
	if Input.is_action_pressed("ui_left"):
		dir -= 1
	if dir < 0:
		dir = -1
	elif dir > 0:
		dir = 1
	var dir_y = velocity.y
	
	if dir != 0:
		set_blend_position(dir)
		if is_on_floor():
			animState.travel("run")
			shadowState.travel("run_shadow")
		else:
			if dir_y < 0:
				animState.travel("jump_loop")
				shadowState.travel("jump_shadow")
			else:
				animState.travel("fall")
				shadowState.travel("fall_shadow")
				
		velocity.x = lerp(velocity.x, dir * speed, acceleration)
		
	else:
		if is_on_floor():
			animState.travel("idle")
			shadowState.travel("idle_shadow")

		else:
			if dir_y < 0:
				animState.travel("jump_loop")
				shadowState.travel("jump_shadow")
			else:
				animState.travel("fall")
				shadowState.travel("fall_shadow")

		velocity.x = lerp(velocity.x, 0, friction)




	if health <= 0:

		if is_on_floor():
			animState.travel("hit")
			shadowState.travel("hit_shadow")
			shadowState.travel("destroy_shadow")
		speed = 0
		jump_speed = 0
		
		yield($damage_player, "animation_finished")
		get_tree().change_scene("res://Stage_1.tscn")
~~~		
2 years later