0 votes

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 physicsprocess 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")
Godot version 3.3 stable
in Engine by (12 points)

1 Answer

0 votes

If the input is "atac" then it is NOT "right" or "left" so

else:
if on_ground == true:
    $AnimatedSprite.play("idle")

will be ran

by (21 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.