I am very new to game development and have no experience with coding. I've been following several Godot tutorials and google results to create my script so it might look very cobbled together. It's supposed to be a platformer.
Making my character walk, idle and jump all seems to be working fine, but when I try to Attack it only plays a millisecond of the first frame. Where did I go wrong and how can I fix this? (I'm still learning so if you can provide explanations with your answers to help me better understand things, I'd really appreciate it!)
extends KinematicBody2D const UP = Vector2(0, -1) const GRAVITY = 20 const ACCELERATION = 50 const MAX_SPEED = 500 const JUMP_HEIGHT = -700 var motion = Vector2() var input_vector = Vector2() var attack_playing = false func _physics_process(delta): motion.y += GRAVITY var friction = false input_vector = Vector2.ZERO if Input.is_action_pressed("ui_right"): motion.x = min(motion.x+ACCELERATION, MAX_SPEED) $Sprite.flip_h = false input_vector.x = 1 elif Input.is_action_pressed("ui_left"): motion.x = max(motion.x-ACCELERATION, -MAX_SPEED) $Sprite.flip_h = true input_vector.x = -1 else: friction = true if is_on_floor(): if Input.is_action_just_pressed("ui_up"): motion.y = JUMP_HEIGHT input_vector.y = 1 if friction == true: motion.x = lerp(motion.x, 0, 0.2) else: if friction == true: motion.x = lerp(motion.x, 0, 0.05) _attack() func _attack(): if Input.is_action_just_pressed("ui_accept"): $AttackArea/CollisionShape2D.disabled = false motion = move_and_slide(motion, UP) _process_animation() func _process_animation(): if is_on_floor(): #Play the jump animation if jump was just pressed if input_vector.y > 0.75: $Sprite.play("Jump") #Run when on the floor and the input is over 0.75 in either direction: elif input_vector.x < -0/75 or input_vector.x > 0.75: $Sprite.play("Run") else: $Sprite.play("Idle") else: #Play the jump animation if the character is moving up if motion.y < 0: $Sprite.play("Jump") elif motion.y > 0: $Sprite.play("Fall") if Input.is_action_just_pressed("ui_accept"): $Sprite.play("Attack") func _on_Sprite_animation_finished(): attack_playing = false