0 votes

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)
Godot version 3.3.stable.official
in Engine by (16 points)

Maybe there's something wrong with the spacebar. Have you tried other keys besides "j"?

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.

1 Answer

0 votes

I switched out my keyboard and now it's working. No idea why, as spacebar appears to work on both old and new ones, but it fixed the issue.

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.