[SOLVED] How to have two different running animations?

Hello! I’m new to Gdevelop and it’s been really easy to learn, but i’ve been stumped on this problem in my top down game. I have two animations where the player is and isnt holding a gun. I’m trying to make the Player have an animation where hes running without any weapons, and one where he does have a weapon. I’ve tried fixing this problem by giving the object a variable that changes after they pick up the weapon, but it ends up only playing the animation when they aren’t moving.
I can give examples of my code if needed, and i’d appreciate the help! I couldn’t find anything online that would help me so I’m making a post about it, sorry if it’s been created before ):

You may use a variable (Status or so) that switches from “Unnarmed” to “Armed”. Now you can name your animations “UnnarmedUp”, “UnnarmedLeft”, and “ArmedUp”, “ArmedLeft”…

You can have an event that changes animations by name using Enemy.Variable(Status)+“Up”

Another way, the way I use, is having the said status variable, I name my animations Unnarmed-90, Unnarmed0, Unnarmed180, Unnarmed270.

And then the event:

The variable Estado(Status), holds the string (Unnarmed, Armed, Idle, Death), and the formula ToString(round(Enemy.Angle()/90)*90), turns the enemy angle into a string that may be -90, 0, 90, or 180.

I have used it for my top down game tries this far.

I tried using this method but I don’t use all four angles for my player sprite. My sprite is facing the left and I flip it when I move left and right to face the right way. Heres an example of my code, I deleted the progress I made but I still have what works. Currently, the idle animation works completely fine when i stand still, but when I start walking it switched back to the normal walking animation without the gun. Sorry for the confusion!

If you use the same logic for walking, I can see a thing.

For idle:

  • Check if the key was released, if so, use the idle animation don’t minding the Gun variable Value
  • If the key was released, and the Gun variable is 1, then you put GunIdle animation

If you have the gun (Gun variable 1) then both events happen (key released, and key released with variable=1) so, if I am correct, the game must be switching from idle to GunIdle animations on each cycle.

If you use the same logic for walking, then the game will be switching between no gun and gun animation each cycle.

May you try:

  • Add to the idle animation a check for the Gun variable being 0. After all, in both events the keys are released so the only difference is the object variable.
  • Check if your walking events have the same logic and try to add the check for 0 value, and the check for 1 value. If the Gun variable is 0, then use Walking, if it is 1, use GunWalking.

Lets see if it works. Good luck

Hey! We got somewhere! All of the gun running animations and the idle one work, but, when I try to go left (press A), my player won’t move if they are holding the gun. Did I do something wrong?

I see the variable hold of the object (or group) weapons… the event is different from the other walking events

It works fine now! Thank you so much! The only problem now is that when I walk up sometimes, the character will glitch back into it’s normal idle animation, without a gun. Anyway to fix that? (:

I am assuming you did the check for the value = 0 in the idle animations too.

May you share how the new idle and walking / running events look like now?

I tried recording a video of the walk progress but my laptop is too slow to play it without lag, so I’m sorry for that. I changed the object value on the normal idle animation without the gun to 0 and it seemed to fix my problem. So thank you again! I appreciate the help :smile:

1 Like

Always a pleasure to help. I am glad you fix it. :slight_smile: