[HELP] Idle animation overrides all other animations on ground.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Elite Cow

Player Script:

https://pastebin.com/Y6EAA0tU

Since I am applying the idle animation to when the player is not moving and is on floor. I am unable to do any other animations while the player is on floor. I just am having difficulty with a solution. I have tried using a raycast2D and disabling it when in “Attack” or “Dance” but I am having issues getting it to re enable at the correct time.

I know there is a concept of state machines but was hoping to try to avoid that for this small game as it is out of my current understanding. If what I’m trying to achieve can it. E done without a state machine please let me know!

Thank you in advance!

Can you please provide some script?

Amateur.game.dev. | 2020-08-30 21:02

I did it is at the tips of the original post.

Elite Cow | 2020-08-31 01:29

I dont have enough experience to explain why that does not work , but from looking at your script I can say the script itself needs to be reorganized, there should really only be three functions in that script one for physics one to check for input and one to play animations, though I don’t often see the convention followed in many tutorials the functions should be in the order from top to bottom as , “play_animation” , “get_input” , “physics_process”. gdscript does not HAVE to be written that way but it is good discipline to follow the convention of older more picky languages, I have only learned a bit of c++ but get pretty far in Godot following the conventions I learned in c++, my current project has 14 animations to make a walk jump run cycle that can jump from left or right foot and I have no animation tree to assemble it for me, I actually think that is more confusing than just doing the script.

your script is made confusing by not following convention, the logic flow of your script is bouncing back and forth into physics process and is not doing enough to be made that confusing… it should have a clear path starting at physics process function >> get input function >>play animation function >> physics process. it just makes the logic flow easier to see and follow.

not functional script but to give an idea of how logic should flow and functions should be organized.

play_animation()
----if is_on_floor and is_moving:
---------if sprite_flipped:
-------------$CharacterRig.scale.x = -1
-------------$PlayerCollision.scale.x = -1
--------else:
------------$CharacterRig.scale.x = 1
------------$PlayerCollision.scale.x = 1
--------animation.play(“walk”)
----if is_on_floor and not is_moving:
---------animation.play(“idle”)
----if is_falling:
---------animation.play("falling)
---------is_falling = false
----if is_jumping:
--------animation.play(“jump”)
--------is_jumping = false

get input()
----if Input.is_action_pressed(“move_left”):
--------motion.x += 1
--------is_moving = true
--------sprite_flipped = true
----if input.is_action pressed(“jump”)
--------is_jumping = true
--------motion.y = jump_speed ( or however you have that working)
other inputs here
----play_animation()

func physics process():
----get input()
----if not is_on Floor and motion.y > 0:
--------is_falling = true
----motion.y += GRAVITY
----motion = move_and_slide_with_snap(motion,snap_vec,up)

like I said not really functional script just shows how functions are organized for task and how logic flows in a circle

hope it is helpful.

ArthurER | 2020-08-31 02:33