#Attack Animations get Called Rapidly by Movement Inputs in my 2D Action RPG

3 messages · Page 1 of 1 (latest)

warped bone
#

I am using Godot 4.1.1. I am a beginner at Godot. It seems that sometimes whenever an attack is inputted, if a directional input is given immediately afterward, it plays another. These can be strung together to create an infinite flurry of attacks. In the video I have a print() function that is printing an is_attacking variable and also whether the attack condition in the AnimationTree is being called. They are both false when the flurry of attacks glitch is occurring. I am baffled.

I've combed through my code and I cannot determine what is causing this. In addition, I copied the code from https://youtu.be/GQD0nk4AGeo this video in a separate project, and the issue was present there, too! I can't escape this. Please help me if you know what's causing this. My code is very amateurish right now.

In today's video we are adding an enemy that can be afflicted with knockback and provide knockback to our player in combat! We also added combo attacks that allow the player to follow up their previous attack in any direction. Thank you all for the recent support! Be sure to reach 100 subs to get free RPG assets as a reward!

New Asset Pack T...

▶ Play video
#

`extends CharacterBody2D

@onready var animation = $AnimationPlayer
@onready var animationTree : AnimationTree = $AnimationTree
@onready var dashTimer = $DashTimer
@onready var dashCooldownTimer = $DashCooldown

const ACCELERATION = 2400
var MAX_SPEED = 14000
const FRICTION = 1100
const DASH_SPEED = 50000

var is_moving = false
var is_dashing = false
var direction : Vector2 = Vector2.ZERO
var dash_vector = Vector2.LEFT
var dash_cooldown = false
var is_attacking = false

func _ready():
animationTree.active = true
velocity = Vector2.ZERO

func _process(delta):
update_animation_parameters()

func update_animation_parameters():
if direction != Vector2.ZERO:
dash_vector = direction
animationTree["parameters/Idle/blend_position"] = direction
animationTree["parameters/Move/blend_position"] = direction
animationTree["parameters/Attack/blend_position"] = direction
if is_dashing == true:
animationTree["parameters/Dash/blend_position"] = direction

if(velocity == Vector2.ZERO) and is_attacking == false:
    animationTree["parameters/conditions/idle"] = true
    animationTree["parameters/conditions/is_moving"] = false
else:
    animationTree["parameters/conditions/idle"] = false
    animationTree["parameters/conditions/is_moving"] = true
    
if is_dashing == true:
    animationTree["parameters/conditions/dash"] = true
else:
    animationTree["parameters/conditions/dash"] = false
    
if(Input.is_action_just_pressed("dash")) and velocity != Vector2.ZERO:
    if dash_cooldown == true:
        pass
    else:
        animationTree["parameters/conditions/dash"] = true
else:
    animationTree["parameters/conditions/dash"] = false`
#

`func move(delta):
direction = Input.get_vector("left", "right", "up", "down").normalized()

if direction and is_dashing == true:
    velocity = direction * DASH_SPEED * delta
else: if direction:
    velocity = direction * MAX_SPEED * delta
else:
    velocity = Vector2.ZERO
    is_moving = false

if velocity != Vector2.ZERO:
    is_moving = true

move_and_slide()

func attack_1(delta):
if is_dashing == true:
pass
else:
is_attacking = true
animationTree["parameters/conditions/idle"] = false
animationTree["parameters/conditions/attack"] = true

func dash(delta):
if dash_cooldown == false:
if is_attacking == false:
if velocity != Vector2.ZERO:
is_dashing = true
dash_cooldown = true

            dashTimer.start()
            dashCooldownTimer.start()
    
            velocity = direction * DASH_SPEED * delta
    
            animation.play("dash")
        else:
            pass
    else:
        pass
else:
    pass

func _physics_process(delta):
if Input.is_action_just_pressed("dash") and velocity != Vector2.ZERO:
dash(delta)
if is_attacking == true:
pass
else:
move(delta)

if(Input.is_action_just_pressed("attack")):
    attack_1(delta)
#print("idling" , "___" , animationTree["parameters/conditions/idle"] ,  "______" , "moving" , "___" , animationTree["parameters/conditions/is_moving"] , "______" , "is_attacking" , "___" , is_attacking, "___" , direction , "___", velocity ,"Idle Blend" , animationTree["parameters/Idle/blend_position"] ,"Move Blend" , animationTree["parameters/Move/blend_position"], "Attack Blend" , animationTree["parameters/Attack/blend_position"] )
print("idling" , "___" , animationTree["parameters/conditions/idle"] ,  "______" , "moving" , "___" , animationTree["parameters/conditions/is_moving"] , "______" , "attacking" , "___" , animationTree["parameters/conditions/attack"] , "______" , "is_attacking" , "___" , is_attacking, "___" , "Is Dashing?" , "___" , is_dashing , "_____" , "Dash Cooldown?" , "___" , dash_cooldown )

func attack_animation_finished():
is_attacking = false

animationTree["parameters/conditions/attack"] = false
if velocity == Vector2.ZERO:
    animationTree["parameters/conditions/idle"] = true
else: 
    animationTree["parameters/conditions/is_moving"] = true

func dash_animation_finished():
is_dashing = false
animationTree["parameters/conditions/dash"] = false
animationTree["parameters/conditions/idle"] = true

func _on_dash_timer_timeout():
pass

func _on_dash_cooldown_timeout():
dash_cooldown = false
`