Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Bacovel |
So I have different animation for run, idle, jump and fall … and I have one for my attack animation. All the animations works how it supose to except for the attack. I am sorry I am new to coding
here is the player code: (just the _physics_process function)
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = 0
if Input.is_action_pressed("right"):
velocity.x += speed
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
elif Input.is_action_pressed("left"):
velocity.x -= speed
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
else:
if on_ground == true:
$AnimatedSprite.play("idle")
if Input.is_action_just_pressed("space"):
if is_on_floor():
velocity.y = jump_speed
if Input.is_action_just_pressed("atac") && contor != 0: # Here is the attack anim
$AnimatedSprite.play("arunca")
contor = contor-1
var sticla = STICLA.instance()
if sign($Position2D.position.x) == 1:
sticla.set_sticla_direction(1)
else:
sticla.set_sticla_direction(-1)
get_parent().add_child(sticla)
sticla.position = $Position2D.global_position
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y >0:
$AnimatedSprite.play("fall")
else:
$AnimatedSprite.play("jump")