Godot Version
4.3
Question
I am trying to add a attack animation for my game, but instead of attacking the idle and/or the running animation just interrupts it, all you can see when you click is the pixels moving for the first frame of the attack. (note I am only 1 week into Godot so pls don’t make fun if my coding is bad)
Code:
extends CharacterBody2D
@export var speed = 300
@export var gravity = 20
@export var jump_force = 300
@onready var ap = $AnimationPlayer
@onready var sprite = $Sprite2D
var attack = false
func _physics_process(_delta):
if !is_on_floor():
velocity.y += gravity
if velocity.y > 1000:
velocity.y = 1000
if Input.is_action_just_pressed("Attack_Input"):
if is_on_floor():
attack = true
ap.current_animation = "Attack_Animation"
await("Idle_Animation")
if Input.is_action_just_pressed("Jump_Input"): #&& is_on_floor():
if is_on_floor():
velocity.y = -jump_force
var horizontal_direction = Input.get_axis("Move_Left_Input", "Move_Right_Input")
velocity.x = speed * horizontal_direction
if horizontal_direction != 0:
switch_directions(horizontal_direction)
sprite.flip_h = (horizontal_direction==-1)
move_and_slide()
update_animations(horizontal_direction)
if Input.is_action_just_released("Run_Input"):
if is_on_floor():
speed = 125
if Input.is_action_just_pressed("Run_Input"):
if is_on_floor():
speed = 175
func update_animations(horizontal_direction):
if is_on_floor():
if horizontal_direction == 0:
ap.play(“Idle_Animation”)
else:
ap.play(“Run_Animation”)
else:
if velocity.y < 0:
ap.play(“Jump_Animation”)
elif velocity.y > 0:
ap.play(“Fall_Animation”)
func switch_directions(horizontal_direction):
sprite.flip_h = (horizontal_direction == -1)
sprite.position.x = horizontal_direction * 4
There is not much too the game yet because the past 2 days I have just been stuck with this error, any help will be appreciated.