0 votes

I've copied the code from another project. I used the same exact setup and now it doesn't work, the character isn't moving or doing anything. The code is below.

extends KinematicBody2D


const UP = Vector2(0, -1)
const GRAVITY = 20
const ACCELERATION = 50
const MAX_SPEED = 100
const JUMP_HEIGHT = -500
var motion = Vector2()




func _physics_process(delta):

motion.y += GRAVITY
var friction = false

if Input.is_action_pressed("ui_right"):

    motion.x += ACCELERATION
    motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
    $Sprite.flip_h = false
    $Sprite.play("Run")


elif Input.is_action_pressed("ui_left"):

    motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
    $Sprite.flip_h = true
    $Sprite.play("Run")

else:
    $Sprite.play("Idle")
    friction = true


if is_on_floor():
    if Input.is_action_just_pressed("ui_up"):
        motion.y = JUMP_HEIGHT
    if friction == true:    
        motion.x = lerp(motion.x, 0, 0.2)
else:
    $Sprite.play("Jump")
    if friction == true:
        motion.x = lerp(motion.x, 0, 0.05)


motion = move_and_slide(motion, UP)


pass
in Engine by (19 points)

Are you using $AnimatedSprite?

Yes and it still doesn't work. Is it a bug?

you have setup those animation in your animated sprite? "Jump", "Idle", and "Run"?

Yep, my character can't even turn around let alone move. Maybe this is a bug.

Can you upload an (if possible: minimal) example project? You'll have to do that when reporting a bug on github anyways.

Please log in or register to answer this question.

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.