0 votes

i have this part of my code :

 if input_vector.x == 0:
    apply_friction()
    animplay.animation = "idle"

else:
    apply_accel(input_vector.x) 
    animplay.animation = "run"

    if input_vector.x > 0:
        animplay.flip_h = false
    elif input_vector.x < 0:
        animplay.flip_h = true

if is_on_floor():
    if Input.is_action_pressed("up"):
        vel.y = jump_height
else:
    animplay.play("anim_jump")
    if Input.is_action_just_released("up") and vel.y < jump_release:
        vel.y = jump_release

the problem is the animation for the jump doesn't want to work, there is just the 1st frame working, and if i want to change :

    animplay.play("anim_jump")

into :

    animplay.animation = "anim_jump"

the others animations will not work properly, they will also play only the 1st frame of their animations

Godot version 3.5
in Engine by (20 points)

1 Answer

0 votes
Best answer

Try:

Func set_animation():
    if input_vector.x != 0:
       animplay.play("run")
   elif vel.y != 0:
       animplay.play("anim_jump")
   else:
       animplay.play("idle")

put this function inside your process function.

this code has not been tested, so it may be wrong

by (286 points)
selected by

sorry for the late response, i had to stop programming for a while.
I had to rewrite your code for me to work.

if input_vector.x != 0 and is_on_floor():
        animplay.play("run")
elif vel.y != 0:
    if Input.is_action_pressed("up"):
        animplay.play("jump")
    if Input.is_action_just_released("up"):
        animplay.animation = "jump"
        animplay.frame = 6

and i decided to change a little the beginnning of the old code i gave here.(your code is in the end)

if input_vector.x == 0:
    apply_friction()

else: 

    apply_accel(input_vector.x) 

    if input_vector.x < 0:
        animplay.flip_h = true
    elif input_vector.x > 0:
        animplay.flip_h = false

if is_on_floor():
    if Input.is_action_pressed("up"):
        vel.y = jump_force
else:
    if Input.is_action_just_released("up") and vel.y < jump_release:
        vel.y = jump_release

    if vel.y > 0:
        vel.y += additional_fall_gravity

var was_in_air = not is_on_floor() 

vel = move_and_slide(vel, Vector2.UP)


if input_vector.x != 0 and is_on_floor():
        animplay.play("run")
elif vel.y != 0:
    if Input.is_action_pressed("up"):
        animplay.play("jump")
    if Input.is_action_just_released("up"):
        animplay.animation = "jump"
        animplay.frame = 6
else:
    animplay.play("idle")

i can clearly say that my code has no sense, and is very painful to read lol, but in the end it worked, so thnks for your help.

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 Frequently asked questions and 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 [email protected] with your username.