0 votes

Animation Problems

I have been following fornclake's Zelda clone tutorials on youtube. After initially achieving the correct results in one project, every attempt to repeat the same has failed.

My problem is that seemingly when I try to switch animations on movement, the animation plays every tick, resulting in it appearing to be frozen as the object moves on screen.

What do i need to do to fix this and animate properly?

This is not the result of an error or anything. I have just been unable to fix this poroblem.

extends KinematicBody2D

const SPEED = 32



  var movedir = Vector2(0,0)

    var spritedir = 'down'

    func _physics_process(delta):
        controls_loop()
        movement_loop()
        spritedir_loop()

        if movedir != Vector2(0,0):
            anim_switch('walk')
        else:
            anim_switch('idle')

    func controls_loop():
        var left  = Input.is_action_pressed('ui_left')
        var right = Input.is_action_pressed('ui_right')
        var up    = Input.is_action_pressed('ui_up')
        var down  = Input.is_action_pressed('ui_down')

        movedir.x = -int(left) + int(right) 
        movedir.y = -int(up)   + int(down)

    func movement_loop():
    var motion = movedir.normalized() * SPEED
    move_and_slide(motion, Vector2(0,0))

func spritedir_loop():
    match movedir:
        Vector2(-1,0):
            spritedir = 'left'
        Vector2(1,0):
            spritedir = 'right'
        Vector2(0,-1):
            spritedir = 'up'
        Vector2(0,1):
            spritedir = 'down'

func anim_switch(animation): 
    var newanim = str(animation,spritedir)
    if $anim.current_animation != newanim:
        $anim.play(newanim)
in Engine by (56 points)

hi, you posted this twice! you can hide this question and continue with the other, so we don have duplicates!.

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.