0 Favourites

[SOLVED]How do I use Timers for firing?

  • Hi guys,

    I would like to say so far the community here has been really helpful and patient with peeps like me who have zero programming knowledge in creating games. I'm currently hard at work in creating my very first game and am really excited to see it starting to come shape.

    Alas i have encountered with another problem, hope someone here can help me.

    Under the system events there's "Compare Time" and "Every X seconds" but those 2 doesn't let me do what i want.

    My sprite is currently firing this way but it goes on and on.

    I need it to stop firing after X seconds, i have downloaded rexrainbow's timer plugins but i can't seem to make it work.

  • Hello,

    "Every X seconds" doesn't work per instance, so if you want several objects of the same type or family firing, only one will.

    You can add an instance variable (named "timer" for example) and at every tick (or every x seconds), for each object, add dt (in system expression) to the timer. In the same time you check if the timer is higher than a value, and if it is, you can fire.

    • Add a "timer" instance variable for your object.
    • Every tick => for each object => add dt to object instance variable timer

    - If timer is higher than value : can shoot.

    I hope it's clear enough. Sorry I don't know the Rexrainbow's timer plugin.

  • There is a built in Timer behaviour. Just set it to trigger after X second and have it turn off an instance variable. Check that variable to see if you should fire or not.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks Nabu0001 and blackhornet for trying to help but sorry i have tried but i can't seem to get it work.

    Below is the attached screenshot

    What i have so far now in the events is having the sprite fly into the screen then starts firing the swirl of bullets both events works separately, the problem right now is after the sprite comes into the playing field, it just stays there and doesn't fire at all.

    I need something to link both events together so that the sprite flies into the screen > starts firing the swirling bullets.

    I wish i could attach the capx file but i have quite a bit of custom plugins and behaviors and i think quite a number of peeps won't be able to open my capx.

  • Well every tick that time = 40 seconds it will fire..

    I'm pretty sure that is only 1 tick..

    You could solve this by creating a sprite and giving it timer behaviour..

    Give enemy3 a boolean variable and toggle the variable on timer

    If enemy3 is boolean fire, if not don't fire bullets..

    If you set the timer on timer you can set the wanted time for the spraying..

  • http://www.blackhornettechnologies.com/ ... Timer.capx

    I use LiteTween, but you should get it if you don't already have it. The idea is similar.

  • Aight, here's something simple that should do it?

    1. Give Enemy3 an instance variable; let's name it "Firing" and make it Boolean (true/false) for simplicity.

    2. In your first event (System > Time = 40 seconds), add the action "Set Enemy3.Firing to True".

    3. In that same event, add the actions "Wait X seconds" (X is however long you want it to last) and then "Set Enemy3.Firing to False".

    4. In your second event, (System > Every tick), change the trigger from "System > Every tick" to "Enemy3.Firing is true".

    This oughta do it. You could also make Firing be True by default and skip step 2, but this allows you to use the enemy in other places without having it explode all over the place.

  • Hi guys, thanks much for your help so far.

    @BlackHornet your capx is very insightful and i learned something from it. It does solves the problem of having the sprite come into the screen and then starts firing for X amount of time. The sprite has the rotate behavior so the bullet patterns works the same as my current setup, in my above event screenshot i created another black square sprite called Enemy3bulletswirl and is set as invisible.

    So the black sprite is the one rotating and firing the bullet instead of the actual ingame sprite.

    The reason being if i were to give set Enemy3 (Ingame Sprite) itself as that or give it a rotate behavior then my enemy will be spinning even thou it does fires the swirl.

    I have tried incorporating your events into mine in the attached above screenshot but it doesn't work, i'm not sure if this conflicts with the "pintoimagepoint" behavior which i'm using or the "moveto" behavior.

    @MikeMead LittleStain i think both of your suggestions are about the same and i tried to follow, up to the point where i don't really get it for MikeMead suggestion in point 4

    4. In your second event, (System > Every tick), change the trigger from "System > Every tick" to "Enemy3.Firing is true".

    I can't seem to find any option to get "Enemy3.Firing is True" the bootlean or any other option doesn't have that. I did went through all of the system events.

    I'm really thankful for your help so far guys but i do would like to apologise if my questions seems too noob, i have learnt a lot while developing my game and am still learning everyday reading the forums

  • blackhornet thanks alot for your help! It finally works! I did some improvements also for my sprite to come into the screen > stop > then fire instead of it firing immediately once it pops into the screen.

    Thanks all for your help guys, very grateful. I have attached screenshot for the working event and hope it helps some others who has the same problems.

  • Hi guys,

    Just an update, i think there's a bug which i'm not sure. The whole event works fine and i duplicate the swirl to fire at the opposite direction and i realised something.

    Some of the bullets seemed to divert away from their current paths to seemly random directions. I have attached a gif as below.

    I don't see that the events itself has any issues as everything works as they are meant to.

  • Thanks a lot this post really helped me

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Depth sorting - almost solved
62 5,162
lucid's avatar
lucid
Unread hot topic
99 10,124
karshinkoff's avatar
karshinkoff
Unread hot topic
0 Favourites
How do I fix this (Solved)
47 1,947
tomi71's avatar
tomi71