automasim platformer how to change animation if ...

HI!

I need help :frowning:

I am trying to figure out how to make a simple platformer automatism character change animation set. for example while moving with left or right arrow keys and pressing another key like “Z” how do I change the animation set ? Basically what I want is for the character to pull out his gun when you press the Z key. I got it to work if he is just standing but not while he is moving. I tried some events but he just kind of "hovers along with the first image.
please Help!

THank you all very much!

First of all, you need to have separated animation sets for stand, walk with gun and without gun and also a separated animation set to pull the gun out.For example:

Animation 0: stand without gun
Animation 1: stand with gun
Animation 2: walk left with gun
Animation 3: walk left without gun
Animation 4: walk right with gun
Animation 5: walk right without gun
Animation 6: pull gun

If you have all the animation sets, there are several ways to do, what I would do, is to store the actual animation number (0,1,2,3,4,5,6) inside an object variable and change animation using the variable, like so:

always (or no condition): Do= player.Variable(animation) to current animation of player

Second, I would use a scene variable to store if the Z key is pressed. For example:

At the beginning of the scene and Z key is not down: Do =0 to Variable(zkeypressed)
If Z key is down and Variable(zkeypressed) = 0: Do =1 to Variable(zkeypressed)
If Z key is down and Variable(zkeypressed) = 1: Do =0 to Variable(zkeypressed)

This way I can use the zkeypressed variable to choose anytime if I want to use weapon or not, here is how:

To change animation, simply check the value of zkeypressed variable and change the value of animation variable
(I guess you are using A and D to move player left and right).

If Variable(zkeypressed) = 0 and key A is not down and key D is not down: Do = 0 to player.Variable(animation)
If Variable(zkeypressed) = 1 and key A is not down and key D is not down: Do = 1 to player.Variable(animation)

By default at the beginning if Z is not pressed, zkeypressed = 0 and because it 0, we change the value of object variable to 0.
Because Object variable is used to to choose animation, and because it value is 0, the stand without gun animation (Animation 0) is playing.
If you press Z, the zkeypressed variable is change to 1. If it 1 tha object variable is set to 1 which is to play stand with gun animation (Animation 1). If you press Z again, zkeypressed is change to 0 and because it 0, the object variable is change to 0 and play stand without gun animation. You can do the same for the rest of the animations.

Maybe sounds a bit complicated, but I hope it helps.

EDIT://

Oh yes, because in GD you can’t check if key is pressed only if key down, you have to make sure to events run only once if a key is down. Otherwise if you press a key (in this case Z) it runs multiple times and change value every frame as long the key is pressed and maybe the animation doesn’t change or you can’t see if it change because it happens super fast.
To make sure the event run only once every time you press a key, you can use a variable like so:

At the beginning of the scene and Z key is not down: Do =0 to Variable(zkeypressed)
If Z key is not pressed: Do = 0 to variable(pressed)
If Z key is down and Variable(zkeypressed) = 0 and Variable(pressed) = 0: Do =1 to Variable(zkeypressed) and Do = 1 to Variable(pressed)
If Z key is down and Variable(zkeypressed) = 1 and Variable(pressed) = 0: Do =0 to Variable(zkeypressed) and Do = 1 to Variable(pressed)

A small suggestion…For switching between 0 and 1 you could use

Condition: On press Z key --> 
Result: Set Variable to 1-self.value

Note that since the latest version, you can add a “Trigger Once” condition instead of using variables when you want an event to be launched only one time when conditions are true :slight_smile:

Thank you all for the info. I am very very very new to all this. I kind of understood ya’all. but hopefully I will just keep trying to figure it out!
I’m a musician classical piano 30 years… not a programmer. But i love my Nintendo! and i want to make my own vintage style games!

Thank you for this free software kudos!
you have made this old goat very happy.