How do I shoot every "variable-timer" once while true

0 favourites
  • 14 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • I'm trying to make an static tower. The tower has a timer variable so my idea is to wait tower.timer seconds and then shoot.

    I thought this was gonna be really easy but I'm getting problems. Either I get the tower shooting infinite bullets nonstop or just shotting the very first time without repeating the "wait loop".

    I was going for something like:

    For each tower > Wait tower.timer seconds > Spawn bullet. This has to happens only once while true, otherwise it will endlessly shoots bullets nonstop, but if I set once while true it will only do this once without repeating the timer countdown.

    Any help?

  • you might want to check the timer behavior for your towers rather than using the wait action.

    https://www.scirra.com/manual/167/timer

    I've made a quick exemple (I added a rotate effect with the rotate behavior just for fun) https://1drv.ms/u/s!AjkoCSebIn9Jiw8M5tPJp_4lOs7g

  • you might want to check the timer behavior for your towers rather than using the wait action.

    https://www.scirra.com/manual/167/timer

    I've made a quick exemple (I added a rotate effect with the rotate behavior just for fun) https://1drv.ms/u/s!AjkoCSebIn9Jiw8M5tPJp_4lOs7g

    Nah, that doesn't do the trick. Each tower needs to have a different timer, that's why the variable.

  • https://1drv.ms/u/s!AjkoCSebIn9JixGkmfKK87AMBeBp I changed it so it uses an instance variable (called fire_timer) to have the 2 towers shooting at a different pace.

    maybe you can work out with that.

  • 1drv.ms/u/s!AjkoCSebIn9JixGkmfKK87AMBeBp I changed it so it uses an instance variable (called fire_timer) to have the 2 towers shooting at a different pace.

    maybe you can work out with that.

    Yeah maybe I can work with that, will give it a try, thanks!

    But still I would like to see an example without the timer behaviour..

  • Yeah, it doesnt work as I expected. I need more controll over it, something similar to what I'm doing, but I'm missing something to make it work.

    This is quite close to what I'm aiming, the problem is, it only works for one tower. If I duplicate the sprite a few times it doesnt apply to every object, just to one.

  • Aphrodite 's example is exactly what you need. You should post an example of how it doesn't work for you.

  • Aphrodite 's example is exactly what you need. You should post an example of how it doesn't work for you.

    It doesnt suit my purpose. Not saying it doesnt work, I'm saying it doesnt meet my expectations and controll over it.

  • Explain what's missing.

  • Explain what's missing.

    blackhornet

    Here's the example given in this thread applied to my game.

    The numbers represent each Tower Timer. As you can see, it doesn't work as expected, since it doesnt follow the timer as it should and the most imporant stuff: It shoots random NON-TIMED bullets.

    The real bullets should be the blue ones, since they're the ones which I set the animation too. The other ones are being created randomly I have no idea how, since the ones I'm creating are set to the blue animation.

    Also as you can see I set the degrees to 90, and it has been working in all my examples, but not on the example given. Not to mention the fact that using a behaviour to control something is not as effective as controlling it through events.

    EDIT: Added For Each on the On Timer and it seems to fix some of the problems.

    Furthermore. I think what I want to achieve is more like a Linear shooting. Something like a domino effect. How can I achieve that?

  • Not sure what you mean by domino effect. 1 then 2 then 3 then 4 and repeat?

  • Not sure what you mean by domino effect. 1 then 2 then 3 then 4 and repeat?

    Exacly. One after each other creating a sequence. Or even 1 and 3 shotting at the same time and 2 and 4 at the same time.

    Because the timer wont create a sequence like I would like to have. I might have 4 turrets shotting at the same time, sometimes 3, sometimes just one, depending on the timer.

  • Various ways to do this. Here's one.

    http://www.blackhornettechnologies.com/Construct2Stuff/TimedFire.capx

    Start with an initial delay, that offsets the firing, then switch to the firing period.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Various ways to do this. Here's one.

    http://www.blackhornettechnologies.com/Construct2Stuff/TimedFire.capx

    Start with an initial delay, that offsets the firing, then switch to the firing period.

    That works nicely. Thank you very much blackhornet!

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