Hey everyone I am trying to make a 2d platformer and I am having a problem where when I trigger my attack, it gets stuck on the first frame then goes back to my idle animation. I know that the idle animation is interfering with it, but I don't know how to fix it. I have tried adding a custom "is_attacking" function but it doesn't help. I have checked the forum and saw a few people with similar/the exact same issue and tried their solutions with out any help.
I could really use the help.
extends KinematicBody2D
# Setting speed and gravity
export (int) var speed = 150
export (int) var jump_speed = -550
export (int) var gravity = 1500
var is_on_ground = false
var is_attacking = false
var velocity = Vector2.ZERO
# MOVEMENT
func get_input():
velocity.x = 0
# RIGHT
if Input.is_action_pressed("right"):
velocity.x = speed
$AnimatedSprite.flip_h = false
if is_on_ground == true:
$AnimatedSprite.play("run")
# LEFT
if Input.is_action_pressed("left"):
velocity.x = -speed
$AnimatedSprite.flip_h = true
if is_on_ground == true:
$AnimatedSprite.play("run")
# JUMP
if Input.is_action_pressed("up"):
$AnimatedSprite.play("jump")
if is_on_ground:
velocity.y = jump_speed
# IDLE
if velocity.x == 0:
if is_on_ground == true:
$AnimatedSprite.play("idle")
# ATTACK
if Input.is_action_pressed("lclick"):
if is_on_ground == true:
$AnimatedSprite.stop()
$AnimatedSprite.play("attack")
# Gravity/velocity
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if is_on_floor():
is_on_ground = true
else:
is_on_ground = false