0 votes

Hi :) I have animation for walk left, right and jump.
All of the animations works, but not the jump.

I cant seem to figure out the problem. So i am here to ask for help.

const UP = Vector2(0, -1)
const GRAVITY = 100
const MAXSPEED = 100
const MAXGRAVITY = 200
const JUMPSPEED = 800

var movement = Vector2()

 func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
    movement.x = -MAXSPEED
    $AnimatedSprite.play("Walk")
    $AnimatedSprite.set_flip_h(false)
elif Input.is_action_pressed("ui_right"):
    movement.x = MAXSPEED
    $AnimatedSprite.play("Walk")
    $AnimatedSprite.set_flip_h(true)
else:
    movement.x = 0
    $AnimatedSprite.play("Idle")

if is_on_floor():
    if Input.is_action_just_pressed("ui_up"):
        movement.y = -JUMPSPEED
        $AnimatedSprite.play("Jump")


movement.y += GRAVITY

if movement.y > MAXGRAVITY:
    movement.y = MAXGRAVITY

movement = move_and_slide(movement, UP)
Godot version 3.3.3
in Engine by (12 points)

2 Answers

0 votes

Hi, I think the issue is that the "idle" animation is overriding the "jump" animation. Before playing the idle animation, you should check to see if the player is not jumping at the moment.

by (7,190 points)

Thank you for the response. How will i go about doing that?
I am new to Godot and making games. So my knowledge isn't that great.

elif is_on_floor():
    movement.x = 0
    $AnimatedSprite.play("Idle")
0 votes

Good day. Between your animations dissonance.
When your heroe jumping changes vector.y but vector.x = 0 and this is identically animation "Idle".
Based on your condition:
if isonfloor():
$AnimatedSprite.play("Jump")

But when you jumping you don't stayon floor. Invalid animation condition.

I would code it like this:

var const UP = Vector2(0, -1)
var const GRAVITY = 100
var const MAXSPEED = 100
var const MAXGRAVITY = 200
var const JUMPSPEED = 800
var movement = Vector2(ZERO)

func physicsprocess(delta):
movement = moveandslide(movement, UP)
movement.y += GRAVITY
if movement.y > MAXGRAVITY:
movement.y = MAXGRAVITY
move()
animation_update()

func move():
if Input.isactionpressed("uileft"):
movement.x = -MAXSPEED
elif Input.is
actionpressed("uiright"):
movement.x = MAXSPEED
else:
movement.x = 0

if isonfloor():
if Input.isactionjustpressed("uiup"):
movement.y = -JUMPSPEED

func animationupdate():
is
onfloor():
if movement.x != 0:
$AnimatedSprite.play("Walk")
elif movement.x == 0:
$AnimatedSprite.play("Idle")
is
on_floor() == false:
if movement.y < 0:
$AnimatedSprite.play("Jump")
if movement.y > 0:
$AnimatedSprite.play("Fall")

by (27 points)
edited by

I apologize for no indents. The editor ignores my indentation.

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.