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:
const ACCELERATION = 9
const MAX_SPEED = 80
const FRICTION = 6
var state = MOVE
var velocity = Vector2.ZERO
onready var animation = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
animationTree.active = true
velocity = Vector2.ZERO
state = MOVE
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")
state = ATTACK
if input_vector != Vector2.ZERO:
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION)
velocity = velocity.move_toward(Vector2.ZERO, FRICTION)
velocity = move_and_slide(velocity)