Take an animation at the frame

Hello there,
I’m working on a finite state machine for my player.
But for example when my player is on ground, switching from left to right, i made an animation
I want that if he is in the animation “switch left to right floor” and jump if he is on frame 3 for example he directly goes to “switch left to right jump” frame 3
How can I do this
If you need some screenshots, feel free to ask me ! :slight_smile:

I understand half of what you are trying to achieve
But something that can help you is condition to check on which animation frame your object is
But i would use it in conjunction with checking on which animation your object is

Well that’s it, but how can i automatically make it do. I have like 120 animations for my player, so is there a way where i can say for exemple if frame 1 for “x animation” then frame 1 for “x animation” else frame 2 etc…

120 animation of what?
I do not understand?

You would need to explain in more detail then maybe there is a way
Even screenshot an example explaining what you do not know how to do

As for now i understand you have 120 animation on one object
You would wish to go with
If player current frame is 3 and animation is jumping
Then do what?

I really do not get what you mean sorry

Ok so imma tryna explain it
I’m making a game like metroid (Metroid fusion based exactly)
All my animations are splits Idle/run/jump/crouch etc…
But I have some animations that are the same with some differences (Run and run shoot for exemple but the torso is in a different position.)
I’d like that when the player run, if he press the shoot button, the animation comes from (for exemple) Run, Frame 8 to Run Shoot Frame 8
Since i’m using a finite state machine (look to some documentation if you don’t know what it is, it would take me a very very long time to set up everythings frame by frame for each animation (My player have 120 animations in total (idle / idle right / jump / jump right etc…)
So i wonder if there is a way to take a frame where it stopped automatically like I asked earlier

For some screenshot Idk what i can provide you. Maybe my transition to switch to switch jump for exemple :

See, if the conditions are met, the switch ground will play switch jump, but will restart at frame 0

I now understand everything perfectly
You kinda shoot yourself in the leg there
But that is because you did not know (as a beginner) and trust me i was there done that
Most likely we all did/were so no shame in that
Option A
Which would DRAMATICALLY reduce number of animations for you would be to split your player animation boy parts into different sprite objects
For example you do not need to have arm on all animations
You could do exact same thing as we all do to attach guns to our players
We create player object we create for example gun point on our player object (in my case arm point)

And now you have separate objects for your player gun (arm for me an i even have arm fire which is that explosion after you fire from gun well i from arm)

Now you place your player on scene but you do the same with gun/arm or you do it via events
Where you create arm/gun and arm fire and delete it when needed
For example i always need to have that arm but i only need arm fire to be there only when i fire bullets

So after i fire it goes tough it’s animation i simply delete it and create again if i fire again

And also you need another action WITHOUT TRIGGER ONCE to move one object to the point you created in my case
Change position of Arm to Player.PointX(ArmPoint) Player.PointY(ArmPoint)

I also rotate it instead of animating it but that is because i wanted it to follow mouse cursor
So basically my player only have animation with his back arm and without his forth arm
Where i could do that animation separately for both sprites and only point his arm into mouse cursor when i fire
But hey who will forbid me from being lazy?
Well you can’t be lazy if you wanna go that route and you will need to animate your cannon arm

This is my test project do not mind all the crap you see there
(i bet you will be interested in Zelda heart system press Z then X and C)
LMB to fire

And this way you would have only your core animations for parts that do not change and you would adjust animation for your arm object
I know Metroid series so i know what you are describing and this is one way to achieve it

Now all you need to do is prepare few events that will check animation frame of your player and set them to animation frame of your arm

And that’s all

All you would need to do as per animation is if your running animation have 7 frames
You would need to cut out your arm from each of these 7 frames and put them into animation of your arm object
And when you change animation of player you would also ALWAYS change animation of arm

So if you have animation arm for player for running with 7 frames
You need to have animation of arm for running with 7 frames
And when you make evnet
D key is pressed
Change animation of player to run
Change animation of arm to run

As for option B
If you wanna keep all of your 120 animations i have VEYR VERY VERY Frankenstine idea of how to do it
And i think there would be better way i just don’t know of any
So i would advise to go with option A

I would simply right click my player hit duplicate and now i have object named player2
I would put player2 on the scene use condition
At beginning of the scene
Hide player2

it only makes him invisible not remove him or whatever
And action to change position of player2 to player
Same as i did show you changing position of arm above
just in this case you go with
Change position of player2 to player.X() player.Y()

And now you could have on player2 only animations which do not include any arm variations
So if you are running you player have his animation set running same as player2
But only player have additional animation called running while firing

Next step is to do same exact thing as i showed you in last picture above
Which is set value of something to something else
But in this case instead of animation you are setting variable
For example you make global variable set it to number and name it FrameNumber
Now you make events like
Player2 current frame = 0
Change Global number variable FrameNumber set to 0

same for frame 1 same for frame 2 and so go on

Then you make another event where
you go with

Where you change current frame of animation for player to global variable FrameNumber

But this method will involve A LOT of tweaking to do exactly same crap to player and player2
For example if you have event to check if player is on floor you need to have same exact event for player2

So if you make event player is on flor and he spacebar is pressed
then change animation to fire
Then you would most likely need to have same exact stuff for player2
So they are in both animation and for example player2 try to play firing while crouching or jumping or vice-versa
They do need to match

I hope you did get the general idea
I am really curious what you gonna choose and i bet you will have more question
Because i am planning to make NOT Mega Man clone but something similar and i also gonna need to go trough same trouble of animation hell as you are going right now

Well what’s your choice?

Thanks for all of theses informations, unfortunatly it’snot “THAT” simple for me since my samus’s sprite have a different sprite for the torso in the “run” than the “run shoot” so i can’t just attach an arm …
I can provide you the 2 different sprites so you see what i’m talking about !
I’m still gonna look for the in frame 1 get frame 1 on other animation

The sprites :
Run :
Run shoot :

I can’t see problem here?
In both cases you remove foreground arm
And simply go with
Adding animation to ARM for run and run shoot
So you would go with

D key is pressed

Change animation of Samus to Run
Change animation of Arm to Run

And another event
D key is pressed
Spacebar key is pressed

Fire Bullet from ArmBulletPoint
Change animation of Samus to Run shoot
Change animation of Arm to Run shoot

Since both animations would have exact same amount of animation frames
You would not need to do any additional matching of frames between both sprites

And there are numerous animations that would use same frames for arm so you would waste lest animation frames on them

In addition for example screw attack
For that you do not need arm at all so you can simply have is arm animation 0 where it is just one frame with blank/empty frame
And only animation of Samus would matter
And while you do screw attack you set animation of arm to 0
Same for morph ball

Does that sound like solution?

I just want to caution you about trying to make it look too perfect. You might be the only one to notice it and making it overly complex will make it tougher to build, debug and you risk degrading performance. It doesn’t matter how nice it looks if it’s unplayable due to a low frame rate. This isn’t criticism. It’s just a caution.

Hey thanks, but when I do something i’m always trying to make it perfect, and for this, a project of a lonnng time, i really want it perfect ^^ Dw i don’t take this as a criticism ^^ Thanks for the warning tho, appreciate ! :slight_smile:

1 Like

But the sprites aren"t the same …

You cut out only one arm
Or maybe both and put them into arm animation sprite object

BTW 3 things
And do not take it as a attack just as a warrning
I just realized that 2 sprite sheets you posted are copyright material since on gdevelop discord it is a big no no to post copyright stuff to which you do not have rights i bet here same rules apply so maybe you should delete them from here

If you do not believe me i can do running and running + shooting animation this way to prove you it is doable

Keith is 100% right
Look imagine you have coins in your game you want to keep track of coins you picked in your level
So what you do?
1st idea of everyone is delete coin when it is picked but then how to spawn that coin or not spawn it if level restarts?
Or if you go to another level and you come back to this level and you want already picked coins to be there?

Well ppl think deleting them and making variable for that which coin is deleted or not is the key
That is perfect solution ppl think same as i see you would
But for player it does not matter if coin was deleted or not
It does not even matter if it is even there
It only matters if coin is there for player to pick up and if it disappear on collision

So best solution
Hide coin with hide action on collision
And now you only need one simple structure variable where you have
Coin 1 boolean variable hidden true or false
Coin 2 boolean variable hidden true or false
Coin 3 boolean variable hidden true or false
And so go on

And now you do not need to respawn anything since all coins will be there when you restart level
And you use that variable to keep picked coins hidden if you change level or load level from save file

And in events you only make that you add idk 5 to your score on coin picked IF coin is visible on collison
So you can’t run into spot where coin is if it is already invisible (after it was picked up) to rank up points/score/money

But no matter what i say or Keith you need to make your own mistakes to learn
And trust me that is better way to learn than reading other ppl messages
I for example needed to NOT use groups because it was stupid for me
End up with mess of events before i did appreciate how easy it is to just disable whole group of events to find something that is causing FPS lag
Loolk how nicely i have it organized

And today i wasted hour looking for event that was causing fps lag over time
to find out here i did lack that inverted condition to NOT take into account units that are already linked to unit selection marker

Without event groups it would take me day or 2 to find it disabling events one by one or few of them at a time

Got it, but since i’m using Finite State Machine, it’s all organised well too
About the Copyright, imma delete the sprites I sent to you.

For the sprite arm, I want to keep it like the original one tho ^^
Imma find a way to do what i want, but you gave me good ideas, thanks !! :slight_smile:

1 Like

So i can only wish you good luck and that you will succeed

1 Like

Super high level:
You are making this more complex for yourself by doing something that Metroid itself doesn’t do. It doesn’t link frames in that way.

That said, you could always track your current frame as a sprite, then manually do whatever logic linking you need. (When you transition states, check the current animation name + the current animation frame, then do whatever animation transition you need. Yes, this means you will need to have a set of conditions for every possible animation transition in each of your states, but this is the bed you made, basically.)

To get the current frame number of an animation, the expression is YourObjectHere.Sprite().

1 Like

Thanks for the reply !
Well then, imma check it for my animation, since it only affects runs and switchs I don’t have many (about 10 for all) ^^

Maybe can you help me more ? I set this like this :

Run Diagonal

And for the run :

Same number of frame I just don’t get this in the whole screen

I would probably start with the “S key is pressed (inverted)” as your parent event, then have subevents for each permutation.

Keep in mind that whenever you’re dealing with animations you should be using “Trigger once” as a condition, otherwise it’ll set that animation (or in this case, the frame of animation) every frame of the game.

1 Like

Oh okay, imma try this right now, wait ^^
thanks for the answer

Well it’s still not working :frowning: