Idle Animation

Hello everybody! I’m making a game right now, and things are going fine. In my game, I wanted to add an idle animation to my character for a little bit of quality of life. You know, in games if your character stands idle for a few seconds they do a fun little animation? I want to do that. I made a nice idle animation for my character that looks great, but that is when I ran in to problems… :frowning:

I made the code so that the animation will only trigger if the following criteria has met:
*5 seconds have passed (Object timer that only starts/ restarts when the player is idle).
*Player is on the floor.
*Player is not moving.
*An object variable for the animation (Attached to the player of course) is set to 0.
*Trigger Once.

If the player moves or jumps, the timer is reset until the player stands still again.
When the above criteria is met, the variable mentioned a second ago will = 1.
When the variable = 1, the animation will play. When the animation ends, the variable is set back to zero, and the timer is reset (Animation does not loop). If the player were to move or jump during the idle animation, it will interrupt the animation, playing the moving animation instead and resetting the timer and the variable back to 0.

Sadly, things aren’t going as I planned then above. When 5 seconds pass while standing still, the player just continues to stay in his normal idle state and not play the animation. The player tries to play the animation, but something is preventing it from doing so. I can’t test to see if the other events work if the player won’t even DO the animation.

Does anybody know what I’m doing wrong?

Can anybody help please??

I’m new to GDevelop, but I would think you don’t need the ‘Trigger once’ condition if you have timers controlling that… I could be wrong though.

In any case, uploading your game would be helpful for others to better see what’s going on.

Or at least an events screenshot :slight_smile:

I kinda got it working after screwing around with the script a little, but I’ve run into some other problems. However, when I find time, I will post a screenshot. Thank you for your reply, and I will try to get the screenshot up in the next reply ASAP. :smiley:

Here you go.

Plushie is the player of course, and “Anim1” is the animation I want him to do.
I just can’t figure out how to get this to work. I want the animation to play, but it doesn’t. Can you help please??

It’s a pity GD5 doesn’t number the events as it makes it harder to explain which ones are being talked about.

First thing I notice is that you have a sub-event that will never happen. If the main event has a condition of the animation of Plushie being “Idle” then there is no point having a sub-event that checks if it isn’t “Idle”.

You seem to have more events than you need and the same action in more than one place. First thing I’d is suggest is putting the checking of the timer being more than 2 seconds as a sub-event of checking if Plushie isn’t moving. That way you only check the timer if he’s not moving.

Plushie is on floor | Set animation of Plushie to "Idle" Plushie is NOT moving |Unpause timer "Idle Animation" of Plushie The animation of Plushie is NOT "Anim1" | |____The timer "Idle Animation" of Plushie is greater than 2 seconds | Set animation of Plushie to "Anim1" Reset the timer "Idle Animation" of Plushie Pause the timer "Idle Animation" of Plushie

All of the above replaces the event immediately above the yellow comment bar in your screenshot. You can then delete all the events beneath the yellow comment bar except the very last sub-event which can be an event of its own to check if Anim1 has finished.
You should also add the “reset the timer” and “pause the timer” actions to any events that check if a movement key is pressed.

Hello again! Sorry for the late reply.
Thank you very much for the help! It is working EXACTLY like I wanted it to! You have just saved me so much time and stress! :smiley: