Plain this is the code that i'm using:
extends CharacterBody2D
var health = 10
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var anim = get_node("AnimationPlayer")
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
anim.play("Jump")
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("left", "right")
if direction == -1:
get_node("AnimatedSprite2D").flip_h = true
elif direction == 1:
get_node("AnimatedSprite2D").flip_h = false
if direction:
velocity.x = direction * SPEED
if velocity.y == 0 and Input.is_key_label_pressed(KEY_E):
velocity.x = 0
anim.play("Sword_Attack")
elif velocity.y == 0:
anim.play("Run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0 and Input.is_key_label_pressed(KEY_E):
anim.play("Sword_Attack")
elif velocity.y == 0:
anim.play("Idle")
move_and_slide()
i was wondering if there is another method of input where i don't need to hold down the button for seeing the whole animation, how can i change the code to make this happen ?