–1 vote

Hi! Still new to gamedev.

Script is attached to a KinematicBody2D ($Player) node. There are three animations in a $Body animated sprite: "Move", "Move Away", and "Idle". 8-dir movement works fine and mostly animating as intended.
Issue is when the Player moves away from the cursor in a diagonal direction. When moving in this specific direction in relation to the cursor, animation is stuck on the first frame of the "Move Away" animation.

I've tried combinations of if statements (messy, I know) but with no luck. Maybe I'm not accounting for the velocity or normalization in the methods? Can anyone tell me what I'm missing or have incorrect? Thanks!

func get_movement_input():
    velocity = Vector2()
    if Input.is_action_pressed('ui_down'):
        velocity.y += 1
        $Body.play("Move")
    if Input.is_action_pressed('ui_up'):
        velocity.y -= 1
        $Body.play("Move")
    if Input.is_action_pressed('ui_right'):
        velocity.x += 1
        if global_position.x < get_global_mouse_position().x:
            $Body.play("Move")
        if global_position.x > get_global_mouse_position().x:
            $Body.play("Move Away")
    if Input.is_action_pressed('ui_left'):
        velocity.x -= 1
        if global_position.x > get_global_mouse_position().x:
            $Body.play("Move")
        if global_position.x < get_global_mouse_position().x:
            $Body.play("Move Away")
    if velocity == Vector2(0, 0): # Cannot be 'else' or the other three inputs before 'ui_up' would be overriden
        $Body.play("Idle")
    velocity = velocity.normalized() * speed
in Engine by (21 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.

Categories