Godot Version
4.3.dev3
Question
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
else:
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
else:
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:
#move_and_slide()
