Charged attacks: Problem with "every X seconds"

0 favourites
  • 7 posts
From the Asset Store
Zombie attack
$16.15 USD
15% off
Zombie attack is a survival game, where you have 2 types of games: Killer and survival.
  • Hi, I've been using Construct for a while, but this is my first time posting on the forums. I guess you'll be seeing more of me in the future as I'll surely get stuck again at some point, but I hope to eventually get good enough to help others.

    <font size="5">Ok, this is the situation:</font>

    I've been working on a game, I have a character (the player) always carrying a melee weapon (separate sprites) pointing upwards (0 degrees).

    When pressing "c" on the keyboard the weapon is tilted back -30 degrees and then it rotates 210 degrees (180 + the 30 it tilted in the begin).

    If the c key is hold for a certain amount of time and then released, the weapon will rotate 390 degrees (360 + the 30 it tilted in the begin)and will be a little faster. Something similar to the "spin attack" in Zelda games.

    The longer you hold c the stronger the attack will be, there are 3 levels of charge (these levels are not relevant for the current problem).

    <font size="5">To do all this, the player's sprite has 2 variables:</font>

    1) charge_lvl:It goes from 0 to 3, the default value is 0 representing a regular 210 degrees attack, from 1 to 3 is a charged 390 degree attack. For the issue at hand there is no difference between 1 to 3 values, it only matters if it is 0 or greater than 0.

    2) lock: It goes from 0 to 1. Default is 0. When the attack "animation" starts I set it to 1, when it ends I set it back to 0. An attack can be performed only when the value is 0, this is to prevent the player to interrupt the attack's animation by pressing c repeatedly.

    I do the attack's "animation" by rotating the weapon 30 degrees, waiting a fraction of a second(0.03 or 0.02), rotating another 30 degrees and so on until the 210 or 390 degrees are completed. At the end of each attack there is a little extra waiting time (0.5 seconds).

    <font size="5">There are 3 events:</font>

    1) c is pressed: This tilts the weapon -30 degrees.

    2) c is down: every X seconds the value of charge_lvl is increased.

    2) c is released: this is divided in 2 sub events: When charge_lvl is 0 and when it is greater than 0. In both cases the attack's "animation" is activated, the only difference is that when charge_lvl is greater than 0 it has additional rotation steps in order to complete the total 390 degree rotation, also, each step in the "animation" is faster (the waits are shorter).

    Ok, that is the way I'm working, now, the actual problem:

    Sometimes when pressing c without holding it does the charged attack(390 degrees) instead of the regular attack (210 degrees). This happens occasionally, try it a few times to see.

    I don't really know where is my error, but I have the feeling it has something to do with the "wait X seconds" condition.

    In my actual game there are enemies, sound effects, visual effects etc, to make sure none of these things had anything to do with my problem I recreated the basics elements associated with the problem into another very basic project. The results were the same so I guess there is a problem with my logic or my understanding of some event.

    (Also, I've tried with Firefox, Chrome and IE, same results)

    So, I'm asking for help to find out a solution to the problem.

    The .capx can be downloaded here:

    mediafire.com/download/67fmqlm7lpmzyj8/temp1.capx

    And these are some images of the project.

    <img src="http://imageshack.us/a/img201/82/o1ed.jpg" border="0" />

    <img src="http://imageshack.us/a/img24/2273/ipjb.jpg" border="0" />

    <img src="http://imageshack.us/a/img833/2126/5lkx.jpg" border="0" />

    Notes:

    * The number on screen is the current value of the charge_lvl variable I added it for debugging purposes.

    * The wait every X seconds sentence is set to high value (9 seconds) in order to make sure that said amount of time is NOT passing end therefore it shouldn't be activating the charged attack.

    Thanks in advance ^_^

  • Move to sub event and problem solved :

    <img src="https://dl.dropboxusercontent.com/u/49548363/charge.jpg" border="0" />

  • use the timer behavior instead of every 9 seconds

    start a regular timer when you set the angle -30

    then on the timer you add to the charge as long as charge <3 and c is down

    : not really

  • mindfaQ

    Yep. Because he's already made logic to reset after melee has completed and on release of C, putting it into the sub event works. However it will instantly increase to 1 so he will need to adjust melee to charge_lvl > 1 probs.

  • Thank you very much for the answers   <img src="smileys/smiley1.gif" border="0" align="middle" />

    I moved the "every X seconds" to a sub event and tested it. The results were the same, usually it worked well, but every now and then it would activate a charged attack instead of a regular attack.

    Then, I used a timer, that did the trick.

    This was the resulting code:

    <img src="http://imageshack.us/a/img541/4773/a3qu.jpg" border="0" />

    Once again, thank you ^_^

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • : nope, because "every x seconds" uses the global time. every x seconds will trigger on (multiples of x) seconds game time (it doesn't start counting from 0 when you press c so to say)

  • it does, because the logic set up resets charge_lvl to 0 when C is released.

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