0 votes

extends KinematicBody2D

const UP = Vector2(0,-1)
const GRAVITY = 13
const MAXFALLSPEED = 200
const MAXSPEED = 80
const JUMPFORCE = 300
const ACELL = 10

var motion = Vector2()
var facing_right = true

func _ready():
pass # Replace with function body.

func physicsprocess(delta):

motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
    motion.y = MAXFALLSPEED

if facing_right == true:
    $Sprite.scale.x = 1
else:
    $Sprite.scale.x = -1

motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED)

if Input.is_action_pressed("right"):
    motion.x += ACELL
    facing_right=true
    $AnimationPlayer.play("Run")
elif Input.is_action_pressed("left"):
    motion.x -= ACELL
    facing_right=false
    $AnimationPlayer.play("Run")
else:
    motion.x = lerp(motion.x,0,0.2)
    $AnimationPlayer.play("Ilde")

if is_on_floor():
    if Input.is_action_just_pressed("up"):
        motion.y = -JUMPFORCE
if !is_on_floor():
    if motion.y < 0:
        $AnimationPlayer.play("Jump")
    elif motion.y > 0:
        $AnimationPlayer.play("Fall")



motion = move_and_slide(motion,UP)
Godot version Godot Engine v3.2.3.stable.official
in Engine by (12 points)

2 Answers

0 votes

You mean player is not jumping and not animated ?
Show code for setting "isonfloor" boolean

Or You mean player is jumping and not animated ?
That is because every frame You force the other 3 animations - left, right and idle. They are connected with all-time if statement , while jumping animation has a split frame to work - on action just pressed. So it works for one frame and is invisible for human eye, because in the next frame IDLE is forced again.

by (2,432 points)
0 votes

Could be loads of things. Add a print / line break to $AnimationPlayer.play("Jump") and confirm it's evaluating true. Check the name of the animation. Check it runs in the editor. Check it's set to the beginning (if it's at the end then playing won't do anything).

I'd strongly recommend that you use AnimationTree. It's one of the most powerful tools Godot offers. Takes a little getting used to but once you're up to speed with it you'll never dream of running animations without it. Up to you whether you use a state machine or a BlendTree - with the latter you can link your animations to the output node via a TimeScale and a "seek" so it's easy to reset it in the editor.

Good luck!

by (813 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.