Attack Animation Delayed!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SiegeNinja

Ok, so in something I only recently began working on, I have quite a simple problem that I can’t seem to find a solution to; the attack animation plays a second or two after I actually press the button.

Here is my code -

extends KinematicBody2D

const ACCELERATION = 500
const MAX_SPEED = 80
const FRICTION = 500

enum {

var state = MOVE
var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get(“parameters/playback”)

func _ready(): = true

func _physics_process(delta):
match state:


func move_state(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_vector.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
	animationTree.set("parameters/Idle/blend_position", input_vector)
	animationTree.set("parameters/Run/blend_position", input_vector)
	animationTree.set("parameters/Attack/blend_position", input_vector)"Run")
	velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

velocity = move_and_slide(velocity)

if Input.is_action_just_pressed("attack"):
	state = ATTACK

func attack_state(delta):
velocity = Vector2.ZERO“Attack”)

func attack_animation_finished():
state = MOVE

:bust_in_silhouette: Reply From: deaton64

it might not be your code, Check the animation state tranistions. You want to change to the Attack state immediate when switching to it.

There are many types of transitions:

  • Immediate: Will switch to the next state immediately. The current
    state will end and blend into the beginning of the new one.
  • Sync:
    Will switch to the next state immediately, but will seek the new
    state to the playback position of the old state.
  • At End: Will wait for the current state playback to end, then switch to the beginning of the next state animation.

All of them are set to immediate, sadly.

SiegeNinja | 2020-07-21 21:31

How about moving the input to before you change the state?

deaton64 | 2020-07-21 21:39