Random individual shooting

For questions about using Classic.

Post » Wed Dec 12, 2012 9:24 am

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.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Wed Dec 12, 2012 11:05 am

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.-Silver-2012-12-12 11:06:07
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Wed Dec 12, 2012 2:45 pm

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.
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Wed Dec 12, 2012 4:16 pm

Mmm,yeah,it sounds good in theory,I'll give that one a go,but everything I've tried looks like it should work!
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Wed Dec 12, 2012 4:28 pm

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.
B
6
S
1
G
1
Posts: 69
Reputation: 1,019

Post » Wed Dec 12, 2012 7:38 pm

That's excellent, Shadowlord! Great thinking
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Thu Dec 13, 2012 2:24 am

Thanks shadowlord,that seems to work perfectly,I changed to using delta time rather than milliseconds,but it works with either,again,many thanks.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests