Animation not playing correctly on button press

0 favourites
  • 3 posts
From the Asset Store
Ninja char for your game! Make your own Shinobi game with this art.
  • I am working on a simple platformer. All the basic stuff like running and jumping is in and the animations for that work fine. I am now trying to add an attack that animates with the press of a key. Instead of the animation playing, the player just jitters for a second and goes back to idle.

    Here is the player Animation Code:

    // player idle

    E: player is not moving - A: set animation to "player_idle"

    // player walk

    E: player is moving - A: set animation to "player_walk"

    // player jump

    E: player is jumping or falling - A: set animation to "player_jump"

    The player controls are just arrow keys or WASD + Space. The moving being the key is down and jump being the key is pressed. The attack is a pressed key, but I am kinda lost has to why the animation will not play. everything in the animation is set up and I have tried some other ways that also do not work.

    I am kinda new so maybe I am just missing something.

  • Events get evaluated from top to bottom every tick(frame)

    In your case, jumping only works because it is placed on the bottom, if you were to place it on top it would also not work. What happens with your attack is likely that you press the button, attack animation starts playing and the next frame the player is "idle/moving/jumping" and the animation is overwritten.

    There are different ways to handle it, for example, you can check if an animation is playing. So you could check "is animation attack NOT playing" and only then you switch it to move/idle.

    I personally prefer to use a state machine, basically an instance variable on the player. Then you set this variable to a definitive state like "falling, jumping, attacking, crawling, dead" And based on that state you set the animation. This prevents overlaps like you have happening where a player is attacking AND idle.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Using the state machine kinda works, but causes issues with the animations themselves. I initially didn't use it because I have run into this issue. When jumping up, the jump animation only plays while they are moving up, and also will play the running animation if I move while in the air.

    Attempts to merge the systems just causes the animations to stop working completely. Also, how would I make an idle state? using a past method of having all keys released causes the issue of other animations acting funky.

    EDIT: Ok, I got it working to an extent by creating a "is_attack" boolean. All the default animations (idle, walk, jump) are now sub-events to an event that says "if is_attack is false" then use these, else play the attack animation. is_attack is made true on its button press.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)