So I'm up to where my attack animations only work when I hold down attack. I also am trying to add a ground finish to my air attack. at first i had the whole animation together but I fixed my jump animation but separating up and down portions of the animation and it worked, so I thought the same for the air attack.
extends KinematicBody2D
var isCrouching = false
var isInAir = false
var isPlaying = true
var onGround = true
var isAttacking = false
var velocity = Vector2(0,0)
const SPEED = 180
const GRAVITY = 20
const JUMPFORCE = -500
func _physics_process(delta):
if Input.is_action_pressed("right") and isAttacking == false:
velocity.x = SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("left") and isAttacking == false:
velocity.x = -SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
elif Input.is_action_pressed("attack"):
if onGround == true and isCrouching == false:
$AnimatedSprite.play("groundAttack")
isAttacking = true
isInAir = false
isPlaying = true
elif onGround == false and isCrouching == false:
if velocity.y > 0:
$AnimatedSprite.play("airAttack")
isAttacking = true
isInAir = true
isPlaying = true
velocity.y = 500
elif Input.is_action_pressed("down"):
$AnimatedSprite.play("crouchIdle")
isInAir = false
isPlaying = true
onGround = true
isCrouching = true
isAttacking = false
if Input.is_action_just_pressed("attack"):
$AnimatedSprite.play("crouchAttack")
isInAir = false
isPlaying = true
onGround = true
isCrouching = true
isAttacking = true
else:
velocity.x = 0
if onGround == true:
$AnimatedSprite.play("idle")
isAttacking = false
isInAir = false
isPlaying = true
isCrouching = false
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE
isAttacking = false
isInAir = true
isPlaying = true
isCrouching = false
velocity.y = velocity.y + GRAVITY
if is_on_floor():
onGround = true
else:
onGround = false
if velocity.y < 0:
$AnimatedSprite.play("jump")
isAttacking = false
isInAir = true
isPlaying = true
isCrouching = false
else:
$AnimatedSprite.play("fall")
isAttacking = false
isInAir = true
isPlaying = true
isCrouching = false
if Input.is_action_just_pressed("attack"):
if onGround == true and isCrouching == false:
$AnimatedSprite.play("groundAttack")
isAttacking = true
isInAir = false
isPlaying = true
elif onGround == true and isCrouching == true:
$AnimatedSprite.play("crouchAttack")
isAttacking = true
isInAir = false
isPlaying = true
else:
if velocity.y > 0:
$AnimatedSprite.play("airAttack")
isAttacking = true
isInAir = true
isPlaying = true
velocity.y = 500
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2)