Random individual shooting

This forum is currently in read-only mode.
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • Hi,does anybody know how to have enemies firing at a random rate?..most importantly independantly of each other.

    At the moment I can get all on screen enemies to fire every x seconds

    Or every x seconds only one of many on screen enemies will fire.

    I want each to have the chance to fire in the randomly set window...

    cheers.

  • I'd be interested to know about this too, since I tried generating wind effects with random spawn times. I gave the Wind object a private variable named "spawn", and set the event up like this:

    Every 2000+Wind('spawn') milliseconds ---> Wind: Set 'spawn' to random(5000)

                                                                          System: Create object "Wind" at position X,Y

    But it didn't work :( It calculated the random figure for 'spawn' once, and then stuck to that figure for the entire playthrough. Different spawn speed for each playthrough, mind you, so it sort of worked, slightly.

    I'm not sure why that doesn't work though. If it did, I imagine your shooting behaviour could work with a similar setup.

  • Just had a thought here. This isn't a perfect solution, but it adds some randomization between different enemies - since your enemies already exist on the layout (I'm assuming you aren't getting the System to create them at run time?) you could set some private variables up for them individually. So for example, give them all a private variable called 'Shoot' and manually set each Enemy's 'Shoot' value to a different number.

    For Each Enemy --->

              Every 50+Enemy('Shoot')milliseconds ---> System: Create object bullet at Enemy.X, .Y

    I haven't tested this, but I think it should work. So an enemy with a 'Shoot' value of 0 would fire every half a second, whilst an enemy with a value of 150 would shoot every 2 seconds.

  • Mmm,yeah,it sounds good in theory,I'll give that one a go,but everything I've tried looks like it should work!

  • Here's another idea:

    Always -> Subtract 0.1 from Enemy('Reload')

    Enemy('Reload')is less than 0 -> Enemy:Spawn bullet

                                     Set Enemy('Reload') to random(2.0)

    It should randomize the shooting pattern for each enemy independently.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's excellent, Shadowlord! Great thinking <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Thanks shadowlord,that seems to work perfectly,I changed to using delta time rather than milliseconds,but it works with either,again,many thanks.

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