Prevent player from moving while the attack animation is playing (AnimationTree)

Godot Version



I am working on a character controller for my top down arpg and this is my first time using the AnimationTree node. After some starting struggles I got the movement and idle animations to work. Now I have a problem where the player can move while swinging his sword, which is not what I want. I want the player to stop while the attack animation is playing. How can I get the animation that is currently playing? Is there an easier way to achieve this than what I want to do here?

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("attack"):
		animation_tree["parameters/attack/blend_position"] = global_position.direction_to(get_global_mouse_position())
		animation_tree["parameters/conditions/is_attacking"] = true
		animation_tree["parameters/conditions/is_attacking"] = false

func _process(delta: float) -> void:
	_input_vector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
	if _input_vector != Vector2.ZERO:
		animation_tree["parameters/walk/blend_position"] = _input_vector
		animation_tree["parameters/conditions/is_walking"] = true
		animation_tree["parameters/conditions/is_idling"] = false
		_previous_input_vector = _input_vector
		animation_tree["parameters/conditions/is_walking"] = false
		animation_tree["parameters/conditions/is_idling"] = true
		animation_tree["parameters/idle/blend_position"] = _previous_input_vector

func _physics_process(delta: float) -> void:
	var target_velocity = _input_vector * max_speed
	velocity = velocity.lerp(target_velocity, 1.0 - exp(-delta * acceleration_smoothing))
	#if the attack animation is not playing:

Ah, it’s actually pretty simple. Just add a variable with a setter function like so

var _is_attacking := false:
		_is_attacking = value

	if not _is_attacking:

Then, add a call method track and set the values in the animation.