I'm working through HeartBeast's Action RPG Tutorial, currently in lesson 9, attack animations. After following the instructions there is a glitch in the attack animations I haven't been able to figure out. I have the 'j' key and spacebar coded as attack.
When I run it, the attack animations work in 7 of the 8 directions when using spacebar. It does, however, recognize the 'j' key for attacks in all eight directions.
Anytime I press spacebar to attack while moving up and to the left, (Vector -1, -1), the code does not recognize the attack command. The debug print statement in my code shows that input_vector is (-1,-1) but does not recognize a spacebar to call the function immediately after.
Here is a link to a copy of my project: https://drive.google.com/drive/folders/18oOJbxFG7inl_MuyfYEiU_aaoLRmby9x?usp=sharing
Here is the relevant code:
extends KinematicBody2D
const ACCELERATION = 9
const MAX_SPEED = 80
const FRICTION = 6
enum {
MOVE,
ROLL,
ATTACK
}
var state = MOVE
var velocity = Vector2.ZERO
onready var animation = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
func _ready():
animationTree.active = true
func _physics_process(_delta):
match state:
MOVE:
move_state(_delta)
ROLL:
pass
ATTACK:
attack_state(_delta)
func attack_state(_delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func attack_animation_finished():
state = MOVE
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")
print(input_vector)
if Input.is_action_just_pressed("attack"):
print(input_vector)
state = ATTACK
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)
animationState.travel("Run")
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION)
animationState.travel("Idle")
velocity = move_and_slide(velocity)