This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi, I need some help with my player animation so far everything was good until I add an idle animation and when I press any direction to walk the player won't change animation it's stuck in an idle frame.

Code of the animation below

#Player Animation 

if (motion.length() > Speed_Idel*0.09):
    if (Input.is_action_pressed("ui_up")):
        Anim = "Walk_U"

if (Input.is_action_pressed("ui_down")):
        Anim = "walk_D"

if (Input.is_action_pressed("ui_left")):
    Anim = "walk_L"

if (Input.is_action_pressed("ui_right")):
        Anim = "walk_R"

# problem starts here the animation won't change back to walking just idle 
#Player walk in a idle state
else:
    if (RayNode.get_rotation_degrees() == 180):
        Anim = "Idle _U"

if (RayNode.get_rotation_degrees() == 0):
        Anim = "Idle _D"

if (RayNode.get_rotation_degrees() ==-90):
        Anim = "Idle _L"

if (RayNode.get_rotation_degrees() ==90):
        Anim = "Idle _R"

if Anim != AnimNew:
    AnimNew = Anim
    PlayerAnimNode.play(Anim)
in Engine by (12 points)

Is there a situation where you are pressing in a certain direction (left, for instance), and the function RayNode.get_rotation_degrees() keeps returning 180, 90, or some other value? Maybe look at what value is returned by RayNode.get_rotation_degrees() (i.e. turn on debugging, or use some breakpoints).

1 Answer

0 votes

You probably need to put the idle part of the code before the walk part. And you can use match to shorten the idle part:

match RayNode.rotation_degrees:
    180:
        Anim = "Idle_U"
    0:
        Anim = "Idle_D"
    -90:
        Anim = "Idle_L"
    90:
        Anim = "Idle_R"

# there's no need for parentheses ( ) around if boolean statements
if motion.length() > Speed_Idel*0.09:
    if Input.is_action_pressed("ui_up"):
        Anim = "Walk_U"
    elif Input.is_action_pressed("ui_down"):
        Anim = "walk_D"
    elif Input.is_action_pressed("ui_left"):
        Anim = "walk_L"
    elif Input.is_action_pressed("ui_right"):
        Anim = "walk_R"

if Anim != AnimNew:
    AnimNew = Anim
    PlayerAnimNode.play(Anim)
by (4,246 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 Frequently asked questions and 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 [email protected] with your username.