#Animation not working properly

4 messages · Page 1 of 1 (latest)

noble venture
#

Hello, so currently I'm having an issue with getting animation to work smoothly. So far most of what I wanted is working as intended except that when going from an idle animation into an attack animation, it sometimes stutters a bit at the start, and secondly if I spam enough I can get the attack animation to endlessly loop as seen in the video I provided down below. Normally if I don't spam it works the way I want to where the attack animation must complete before the character can even move.

But yes, I need help solving this weird endless animation glitch. Any and all help would be appreciative.

Here is the current code with a video of the issue. If you need any more information let me know and I'll gladly provide more.

#

extends CharacterBody2D

var speed := 20000.0
var direction : Vector2 = Vector2.ZERO
var is_attacking : bool = false

func _ready() -> void:
    %AnimationTree.active = true
    %AnimationTree.animation_finished.connect(self._on_animation_finished)

func _process(delta: float) -> void:
    if Input.is_action_just_pressed("attack") and not is_attacking:
            start_attack()

    if not is_attacking:
        direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
        move_character(direction,delta)

    update_animation_parameters()

func move_character(direction: Vector2, delta: float) -> void:
    velocity = direction * speed * delta
    position += velocity * delta

func update_animation_parameters():
    if velocity == Vector2.ZERO and not is_attacking:
        %AnimationTree["parameters/conditions/idle"] = true
        %AnimationTree["parameters/conditions/is_moving"] = false
    elif velocity != Vector2.ZERO and not is_attacking:
        %AnimationTree["parameters/conditions/idle"] = false
        %AnimationTree["parameters/conditions/is_moving"] = true

    if Input.is_action_just_pressed("attack") and not is_attacking:
        is_attacking = true
        %AnimationTree["parameters/conditions/attack"] = true

    if direction != Vector2.ZERO:
        $AnimationTree["parameters/attack/blend_position"] = direction
        $AnimationTree["parameters/idle/blend_position"] = direction
        $AnimationTree["parameters/move/blend_position"] = direction

func start_attack():
    %AnimationTree["parameters/conditions/idle"] = false
    is_attacking = true
    %AnimationTree["parameters/conditions/attack"] = true

func _on_animation_finished(anim_name: String) -> void:
    if anim_name.begins_with("attack_"):
        is_attacking = false
        %AnimationTree["parameters/conditions/attack"] = false

https://imgur.com/a/rqSF8nQ

viscid tide
#

Maybe start with placing print_debug statements to identify the nature of the problem?

white trout
#

In my case my state machine was changing so fast that it didn't have the chance to end or start animations properly. I don't quite remember the problem or how I fixed it but I imagine it's that.