Animation State Machine

Get help using Construct 2

Post » Tue Oct 29, 2013 5:49 pm

Hello there!
Ive made some games with C2 so far, but Im at a loss when controlling animations in an efficient manner.
Id like to have several states like, for example:
-Idle
-Walk
-Run
-Jump
-Falling
-Attack

But I cant seen to make the transitions between those states in a clean way. So, how do I make a controller for those animations that doesnt look like crazy if I need to insert a new animation?
Also, is there any way to queue animation states?(For example, two idle states or a double jump)

If you could provide an example I would be very grateful!

Thanks!
B
38
S
8
G
3
Posts: 440
Reputation: 6,878

Post » Tue Oct 29, 2013 7:27 pm

One way to approach it is to separate out each animation to play only when a specific set of events is true.

eg: play the crouch walk animation if the down and left keyboard buttons are pressed.

which would look like

keyboard On Left Arrow is Down-> play crouch walk animation
keyboard On Down Arrow is Down

repeat this for each and every type of unique movement you want the player to do.

To transition between them nicely, you will also want to make use of the "on animation crouch walk" is finished events.

So after you are done crouch walking you might trigger the play "stand up" animation so it looks nicer and doesn't just POP into place.

so that would look like

PlayerSprite On Animation "crouch walk" finished -> PlayerSprite set animation to "standup" (play from beginning).

If you find that animations are interrupting each other....
For example. if you player is playing a falling animation and you press left or right and that makes him start walking again in the air. you can make use of the "is playing animation" event. and then invert it and make it a "is NOT playing" event condition

eg:

keyboard on key down "Left"
(a second condition) PlayerSprite is NOT playing animation "falling" -> play "walk left" animation

this way the "walk left" animation will only play provided the "falling" animation isnt currently playing.
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Wed Oct 30, 2013 2:31 pm

Thanks @justifun!
Im worried that working with exceptions(ie:when not falling), the code becomes a mess and inserting new animations is a shore. ;o
B
38
S
8
G
3
Posts: 440
Reputation: 6,878

Post » Wed Oct 30, 2013 2:42 pm

You could give the player a variable playeraction and set it to "walking","falling","jumping","shooting"
Then instead of checking animation you only have to check which action the player is performing.

so on left button touched -
player.playeraction = "walking"
- player set action to "jumping"

player compare variable playeraction = "jumping"
system trigger once
-player simulate platform pressing jump

etcetera.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Oct 30, 2013 2:52 pm

I've made a variable to tell which animation is playing, and instead of changing the animation when keys are pressed and such, I just change it.

For the basic platform movement, I check if it's 0 then check if the character is walking, jumping, etc.

For other things, like using abilities, swimming, going up a ladder, I use other numbers.



(Sorry for the messy code, I know I could use sub-events to make it look prettier but I haven't got to cleaning it up yet)
B
125
S
43
G
41
Posts: 849
Reputation: 28,260


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 51 guests