How can i make a second, third, fourth, etc. attack in my 2D game?

Attention Topic was automatically imported from the old Question2Answer platform.

Im making a 2D RPG game… You can move around in a open world. So i made a attack (with a sword) but im not sure how to make a second attack. I’m planning to do a magic spell as my second attack but i can’t find out how. The animation is already finished and i already set it up in the AnimationPlayer + AnimationTree. In my player script logically it have to work, but when I press the button for the second attack (Key “2”) the player just freezes…

Here is my player-code:

``````extends KinematicBody2D

export var ACCELERATION = 500
export var MAX_SPEED = 80
export var ROLL_SPEED = 110
export var FRICTION = 500

enum {
MOVE,
ROLL,
ATTACK,
ATTACK2
}

var state = MOVE
var velocity = Vector2.ZERO
var roll_vector = Vector2.DOWN

animationTree.active = true
swordHitbox.knockback_vector = roll_vector

func _process(delta):
match state:
MOVE:
move_state(delta)

ROLL:
roll_state(delta)

ATTACK:
attack_state(delta)

ATTACK2:
attack2_state(delta)

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:
roll_vector = input_vector
swordHitbox.knockback_vector = input_vector
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationTree.set("parameters/Attack2/blend_position", input_vector)
animationTree.set("parameters/Roll/blend_position", input_vector)
animationState.travel("Run")
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

move()

if Input.is_action_just_pressed("roll"):
state = ROLL

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

if Input.is_action_just_pressed("attack2"):
state = ATTACK2

func roll_state(delta):
velocity = roll_vector * ROLL_SPEED
animationState.travel("Roll")
move()

func attack_state(_delta):
velocity = Vector2.ZERO
animationState.travel("Attack")

func attack2_state(_delta):
velocity = Vector2.ZERO
animationState.travel("Attack2")

func move():
velocity = move_and_slide(velocity)

func roll_animation_finished():
velocity =  velocity / 2
state = MOVE

func attack_animation_finished():
state = MOVE

func attack2_animation_finished():
state = MOVE
``````