0 votes

Hello! Im glad to be here!
I'm new to game development and Godot.
Ive never programmed something before. So I did this simple scene, just a ball, with a walking animation, some simple ugly tiles and the possibility to jump.
When playing the game and also in the viewport of Godot the tiles sometimes disappear. The walking animation sometimes runs smooth, but most of the time only the first 3 frames are being played.
Instead of an idle-animation I used $AnimationPlayer.stop(), but when I stop walking (pressing right) sometimes the animation freezes but it doesnt swap back to the first frame. Same when jumping. I hope someone can help me :(

My PlayerScript (Attached is a Camera 2D, an AnimationPlayer, a collisionshape2D (circle), and a sprite Node):

extends KinematicBody2D

const SPEED = 60
const GRAVITY = 400
const JUMP_POWER = 150
const UP_VECTOR = Vector2(0,-1)

var screen_size
var movement = Vector2()



func _ready():
     screen_size = get_viewport_rect().size



func _process(delta):
    movement.x = 0



    if is_on_ceiling() or is_on_floor():
        movement.y = 0

    movement.y += GRAVITY * delta

    check_key_input()

    move_and_slide(movement, UP_VECTOR)

    set_animation()

    clampPlayertoScreen()


func clampPlayertoScreen():
    position.x = clamp(position.x, 0, screen_size.x)
    position.y = clamp(position.y, 0, screen_size.y)


func check_key_input():

    if Input.is_action_pressed("left"):
        movement.x = -1 * SPEED

    if Input.is_action_pressed("right"):
        movement.x = 1 * SPEED
        $AnimationPlayer.play("Run")

    if Input.is_action_just_pressed("jump") and is_on_floor():
            movement.y = -JUMP_POWER

func set_animation():
    if movement.x < 0:
        $sprite.flip_h = true
        $AnimationPlayer.play("Run")
    if movement.x > 0:
        $AnimationPlayer.play("Run")
        $sprite.flip_h = false
    if movement.x == 0:
        $AnimationPlayer.stop()
    if is_on_floor() == false:
        $AnimationPlayer.stop()
in Engine by (12 points)

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.