How do I set and play attack animations on landscape games

0 favourites
From the Asset Store
A complete set of Graphic, User Interface element to build 2D mobile game or PC game.
  • Hey there

    I've been working on an isometric-view game for a while, and I still can't manage to get the attack animations working correctly. They always get stuck on the first frame, so I would like to know if I'm doing anything wrong. I'll attach a screenshot of the event sheet for now, since some of the assets still need to be worked on and I would rather not share the capx until then.

    If it's possible, I would also like to know how to spawn an object (in this case, a bullet) with a small delay after the start of the attack animation.

    I'm sincerely sorry for not being able to share the capx, but I trust this screenshot is good enough information for you folks.

    (FYI: The "Stop animation" in event #22 isn't affecting the attack animations as far as I know. It's just there to make sure the walking animation stops before the attack animation begins. I tried deleting it and the outcome was the same)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try the following:

    1) Remove the Stop animation from event 22 (it is not needed and it might cause problems after all)

    2) Add the condition "Is not Attacking" (add the "Is Attacking" and invert it) on the event 15.

    Also, make sure that the speed of the animations isn't 0.

    As for the spawning, either add a "Wait" action in your events and after that add the "spawn an other object" action, or if you want the spawned object to come out from a specific place at a specific frame,

    1) go into the animations

    2) find that frame

    3) add an image point to where you want the object to be spawned from

    4) create a new event and as a condition add the "compare frame" = to the frame you want

    5) add the "spawn an other object" action (don't forget to choose the correct image point)

  • Alright, here's the updated event screen. Made some changes of my own so the character would stand still while shooting, and the animation is working correctly now (thanks to your tips, of course). However, even if I disabled 8Direction while shooting, I can still make the character look to the left, down and up, which pauses the animation and makes it start over in the new direction. Also, the character is shooting way too many bullets per attack, as if it had some sort of burst-fire mode selected. Made some changes to make it fire less projectiles but it's still shooting way too many. Is there any way to limit the attack to 1 bullet?

  • You want your character to stop moving when he is firing right?

    If so, you don't have to use the disable/stop 8direction movement (event 23) Instead add a "X IsAttacking" condition as event 2 and nest the (current) events 2,3,4 and 5 as sub-events. You should have then:

    if Player "X IsAttacking"

    -------Keyboard Down Arrow is down ----> Simulate 8direction pressing Down

    -------Keyboard Right Arrow is down ----> Simulate 8direction pressing Right


    As for the rapid fire, just add the "Trigger once while true" condition on the event 23 (together with the "IsAttacking")

  • It didn't work, sadly. I can move while attacking and then the character gets stuck in his first walking frame whenever he's standing still. Don't worry though, my temporal fix is still working fine so I can continue testing everything else.

    What did work, however, was the rapid fire fix. I had to put "Trigger once while true" on event 25 though, since putting it in 23 made the "spawn another object" event useless.

    By the way, the bullet only goes to the right at the moment. What do you recommend in order to make it go up, left and down, accordingly? Right now the bullet is set to spawn at the third (#2) animation frame. I suppose I should try to use "set angle" to change its trajectory, or should I create a new object with a mirrored/upside-down bullet?

    I apologise for the tardiness in my reply. I wasn't home, but please keep in mind I'm very interested in getting this to work and I appreciate your help.

  • You are doing something wrong. It should work and it is wiser to check the variables than constantly disabling/enabling the behaviors.

    You are right about the trigger once, the advices were from my head, I didn't suspected that.

    I think this is what you want. I've altered one of my examples that is lurking somewhere in the forums, in order to fit your instructions. Tell me if something doesn't work as it should.

  • I compared your capx with my project, and for some reason, even after doing the same changes, the character still moves while attacking. I really don't know why this is happening.

    Here's an updated version of all movement events. I seriously can't spot what's causing this.

  • EightMan I haven't tried setting actions while comparing to an animation frame, but you can try adding a System - Every X.X seconds in event 30, try with somethin like 0.3.

    Also, maybe you should try checking for the IsAttacking variable on all your movement events (5,6,7,8) and removing event no. 4. Besides, you are setting the IsAttacking variable on "W is pressed" and everything else to "X is Down", pressed and down are different.

    I can't give it a try right now but, hope that helps.

  • Have you disabled the default movement on the 8direction properties..? I think that this is the culprit.

    On a different note, I remember that placing the bullet creation above the direction conditions solved some double firing problems. If you encounter this, move the event 29 just below event 24 (in essence, make it the first sub-event).

    donelwero the sub-event 30 ensures that the triggering happens at the correct frame and it's fps independent. The every x seconds is somewhat abstract and inaccurate.

    Also the "Is NOT attacking on event 4 is checked first and only when it holds true the following sub-events execute. The "is pressed" and "is down" on this matter are irrelevant.

  • Alright, that fixed it!

    Thanks a lot man. I learned a lot with this.

    By the way, since we're here, could you point me to any enemy attack animation tutorials? I made an enemy that is supposed to stop and attack just like the playable character, and I'd like to know if anyone else has made enemies that move in only 4 directions and attack from up close (which I assume should be done with Pathfinding but I could be wrong).

  • I am glad that you made it work!

    Now, I haven't really done any search for enemy AI yet, didn't need to. I am not sure about the 4 directions and the path finding though. The only true benefit by using it will be if you have obstacles. Otherwise, using events you will probably have more control around the enemy's movement.

    This is a capx I had made for an other topic, the goal was for the enemy to move vertically until he line him self up with the player and then move towards him, in a Double Dragon fashion. You can get some info out of it that might help you build your own movement.


    As for the attack, just make a distance comparison* (or use an invisible sprite that is bigger than the enemy's sprite and check for overlap) and when true, set an Instance variable "Attack" to true and create the necessary events for the enemy's attack.

    *The distance comparison should look like this:

    (System - Compare 2 values)

    distance(Player.X, Player.Y, Enemy.X, Enemy.Y) < any number you want ----> Player set Boolean "Attack" to true

    distance(Player.X, Player.Y, Enemy.X, Enemy.Y) > the same number as above ----> Player set Boolean "Attack" to false

  • I'm actually using Pathfinding at the moment since there are obstacles in the map. What I can't figure out is how to make the enemy play the right animations while walking in a specific direction. Right now, they can find the player quite easily, but they don't actually use any of the animations I set for them. I reckon I should do something similar to what I did with the character's movement animations (Setting the direction, then playing an animation depending on which one is active). I disabled diagonals and "rotate object" to avoid problems, and I think I have an idea on how to make the enemy attack when it's next to the character, but I would appreciate any help on how to make the enemy walk in the right direction while moving.

    PS: Using "Find path to (Character.X, Character.Y)" the enemies go straight for my location, but they never move from there afterwards. Any idea on how to update my location?

    Update: The enemies are dealing damage while playing their animations now.

  • I understand. I' ve updated and attached the example. It's not perfect, I don't know how to calculate the angles in a predictable manner. Some times, C2 returns a 180 degree value and other times it returns -180 degrees, which in essence are facing at the same same way, but brake down the conditions which set the direction variable... I am sure there is a mathematical formula that fixes that, but I am unaware of it. For the time being, try to improve upon this, until some wise forum member comes to the rescue!

  • Ok, I think I fixed it. Check it out below. On a side note, perhaps gameplay wise it would be better to use the angle(enemy.X, enemy.y, player.X, player.Y) to determine the attacking direction/animation, since there are moments that the enemy moves toward the player but the direction he is moving doesn't match the direction he should be facing/attacking.

  • Do you known if it could be possible to swap out the current global "ang" variable for a normal instance variable? assuming there's more than one enemy on screen, wouldn't this make all of them play the same animation regardless of where they are?

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