Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Redmouse9 |
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: Shared ARPG Tutorial – Google Drive
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)
Maybe there’s something wrong with the spacebar. Have you tried other keys besides “j”?
Ertain | 2021-06-09 07:42
Based on another suggestion I swapped out my keyboard and it’s now working. I have no idea why. The spacebar appears to be working fine on both, just for some reason on the old one not while the up and left arrow keys were pressed.
Redmouse9 | 2021-06-09 19:53