How do I set states with variables? Not sure what's wrong

0 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Also, thank you Trultz for the new information (sorry I couldn't reply via PM, I don't have enough rep yet). I'm rebuilding everything slowly now and I will try your and Minor's methods as soon as I'm able. Thank you very much!

  • I think I got it working by just having the enemy hitbox overlap an invisible player bounding box instead the two imagepoints. Probably was a combination of the overlapping imagepoints not working exactly as I thought (hope it's not a bug though) and the unusual movement system I'm trying to make. Thanks very much to everyone who suggested ideas!

    I do have another slightly-related question if you don't mind (and I'd rather not create a whole new thread for in case it's a very simple fix). Now that the enemy does stop once within range and begin to attack (by calling a random animation), I can't figure out how to force an animation to play all the way through before calling upon another random value. They keep getting interrupted as the random command is called 60 times per second.

    I tried Trigger Once While True and a few other methods I read in tutorials and none of them seem to work here. Like I said, I'm probably missing something very obvious, but I posted an example of the code with blank actions and was hoping someone could give me some advice. All of the movement that is now working is included in that example too. Hopefully it might help someone else avoid all the frustration I went through!

    Sorry to ask again and thanks in advance for your help!

    [attachment=0:2y59q18y][/attachment:2y59q18y]

  • If your attack animations don't loop you can have this check along with your enemyattack = x conditions

    enemy Animation Frame = enemy.AnimationFrameCount - 1

    This checks if the sprite is in the last frame of its current animation. However, this may cause the animation to be cut a little short (because the check could come as soon as the last frame starts), so I recommend you pad all of your attack animations by repeating the last frame at the end

  • I'm sorry, but I don't understand how to write the code you recommended. For my example, would it be something like Add Condition -> Enemy Sprite -> Compare Frame -> Equal to -> "enemykick1" = enemy.5 -1 (I don't know how to write the last bit)?

  • I'm sorry, but I don't understand how to write the code you recommended. For my example, would it be something like Add Condition -> Enemy Sprite -> Compare Frame -> Equal to -> "enemykick1" = enemy.5 -1 (I don't know how to write the last bit)?

    That's the condition. Replace Bullet with enemy of course. AnimationFrameCount is an expression that returns the amount of total frames in the current animation of the sprite.

  • I just noticed that Sprite has triggers to check if animations are finished.

    Just have an instance variable on your enemy object "isCurrentlyAttacking" which you set to 1 when you start each animation, and have a subevent just below the 'enemystate = "attack"' condition to check for "enemy on any finished" with an action to set "isCurrentlyAttacking" to 0. You only start an animation if "isCurrentlyAttacking" is equal to 0

    (I didn't see the condition before because I was testing below another trigger, so it didn't show)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • :deleted last post, I think I got it working: Does this look right? Thank you very much!

    [attachment=0:2bj5l5da][/attachment:2bj5l5da]

  • :deleted last post, I think I got it working: Does this look right? Thank you very much!

    [attachment=0:zggap7g7][/attachment:zggap7g7]

    The last 3 events should be subevents of the first one, because if not you'll have them starting the animations even if they're not in the "attack" state. Aside from that, it should work perfectly

    Tell me how it goes

  • In fact, you could transform those last 3 events into only one, if you keep the names of the animations in an array and then do

    enemy_bbox isCurrentlyAttacking = 0 -> enemy Set animation to AnimationArray.At(int(random(3)) (play from beginning)

    ----------------------------------------------------- -> enemy_bbox set isCurrentlyAttacking = 1

  • It actually worked without making the last three events a subset of the first one, but I did it anyway because that could cause trouble later. Thank you very much!

    I'm not quite familiar with arrays yet, but I will make a note of what you wrote and try to put it to use later. Thanks for that too!

    One additional problem came up during the attack animation playback mess, but I hate to keep asking questions. In that large code example earlier, it shows the enemy will move towards the player's bounding box by checking X, moving, and playing the walking animation. The only thing is that in this case, the animation does not get interrupted when the enemy overlaps the player's bounding box, and enemy pauses to finish its four frame walking animation before the enemystate is set to "attack". I tried putting Stop animations, Trigger Onces, etc, but whenever they do work, they also stop the random attacks from beginning. Do I need to make another variable in order to cut off animation immediately?

    Again, thanks a lot for your time. I hope that this discussion and your advice will help other users too.

  • Where did you try using Stop Animation?

  • As an action for enemy_bbox is overlapping player_box (and I don't know why there were two of those 'overlapping playerbbox' there, I removed one).

  • As an action for enemy_bbox is overlapping player_box (and I don't know why there were two of those 'overlapping playerbbox' there, I removed one).

    Strange, it should work there

  • Here's where I put it, is this still correct? The logic seems to make sense to me, but the enemy always plays all four animation frames before switching to enemystate "attack".

    [attachment=0:20dq7r4x][/attachment:20dq7r4x]

    Could you tell me where I could find in the manual (or elsewhere) how to write the expression for checking if any of a number of animations have finished? Basically I want to do something like:

    Enter the name of the animation that has finished: Animation: "enemykick1", "enemypunch1","enemypunch2" (that doesn't work of course)

    I seem to be able to find everything I don't need to know, but never what I do.

  • Here's where I put it, is this still correct? The logic seems to make sense to me, but the enemy always plays all four animation frames before switching to enemystate "attack".

    [attachment=0:2um2sjtn][/attachment:2um2sjtn]

    Could you tell me where I could find in the manual (or elsewhere) how to write the expression for checking if any of a number of animations have finished? Basically I want to do something like:

    Enter the name of the animation that has finished: Animation: "enemykick1", "enemypunch1","enemypunch2" (that doesn't work of course)

    I seem to be able to find everything I don't need to know, but never what I do.

    I think I found the problem. You should put the overlapping condition before the other two, and use System -> Else.

    Most of the time, if two sprites are overlapping, their X coordinates aren't necessarily equal, so, for example, let's say that your enemy is already walking right towards the player when you enter the base level event, and enemy_bbox is overlapping player_bbox, but is still a little to the left (enemy_bbox X < player_bbox.X). You first enter the "enemywalkR" subevent, and it waits for 0.1 seconds (I'm guessing that's enough for some frames of the animation that was already playing to play out), it starts playing the animation again and only then enters the stop event.

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