I want enemies not to shoot all at the same time.

Get help using Construct 2

Post » Wed Jun 06, 2012 10:02 am

Greetings!

I'm learning Construct by making a small shoot'em up.

Actually, the game create 1 enemy every second for 6 seconds :



I would like them to start shooting (for example 1 shoot every 1.2 seconds) when the are created.

Actually, if there are 6 enemies at the same time on the screen, they all shoot at the same time.

Any idea to change this ?
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Wed Jun 06, 2012 10:06 am

Try doing it with UID picking.
Zelda Gamekit (my project)

Example capxs I have made:
Zelda-Style Inventory
Zelda Hearts System

The unwritten "How do I" capx etiquette! Nearly always provide a capx of the problem you have, and try to isolate the problem and/or no capx above 10 MB. :)
B
38
S
19
G
26
Posts: 438
Reputation: 16,581

Post » Wed Jun 06, 2012 10:22 am

just use a "for each" loop, that should handle each instance separately, instead of having them all shoot at the same time.

For Each Object "enemy":
--Every "enemy2.firerate" Seconds: enemy2 - spawn bullet
B
64
S
8
G
9
Posts: 290
Reputation: 8,590

Post » Wed Jun 06, 2012 10:37 am

I'll try that, thanks a lot!
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Wed Jun 06, 2012 4:03 pm

[QUOTE=brent_hamel] just use a "for each" loop, that should handle each instance separately, instead of having them all shoot at the same time.

For Each Object "enemy":
--Every "enemy2.firerate" Seconds: enemy2 - spawn bullet[/QUOTE]

I tried :



But it doesn't seem to work, none of my enemies2 are shooting (except the "original" one outside of my layout).

I didn't try with UID picking, I think it's a little bit complicated for me at this time. I'm a true beginner :DCanapin2012-06-06 16:08:14
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Wed Jun 06, 2012 6:06 pm

Use a instance variable instead of "every X seconds".

Add an instance variable to enemy2 and call it "timer". Then replace your event 12 with these two events:

enemy2 : timer > 0
------- Enemy2 : Subtract dt from timer

enemy2 : timer <= 0
------- enemy2 : Spawn plasmaBullet
------- enemy2 : Set timer to enemy2.fireRate

B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Wed Jun 06, 2012 11:47 pm

Here is an example that I did for someone who had problems with everyone shooting at the same time. Everything happens randomly. You may find it useful.

RandomExperiments.capx

On start of layout, creates a random number of enemy sprites at random locations, and then randomly creates new or destroys existing enemies. At random intervales choose an enemy and has it shoot in a random direction. (Ignore the part about the local variable. That was to demonstrate how to handle another problem he was having.)



B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Sat Dec 15, 2012 9:15 am

[QUOTE=R0J0hound] Use a instance variable instead of "every X seconds".

Add an instance variable to enemy2 and call it "timer". Then replace your event 12 with these two events:

enemy2 : timer > 0
------- Enemy2 : Subtract dt from timer

enemy2 : timer <= 0
------- enemy2 : Spawn plasmaBullet
------- enemy2 : Set timer to enemy2.fireRate

[/QUOTE]


Thank you for this. I was having a problem using the "every x seconds" as well. It's a shame you can't combine this with (or after) a trigger that selects a single object (like "overlapping an object", or "health <= 0). Was seriously driving me crazy.

Really though, it'd be a lot easier to use the built in timer (every x seconds) if you could have it reference each instance of an object individually, like most of the other conditions. I mean how often are you going to have multiple copies of the same object? Seems like every game has a few of those, and then to make them all not be the exact same you set some randomness. In my case I just wanted them to all jump a little different than each other, so a random timer would solve this perfectly. Too bad the built in one references all instances of the object, even if picking using a instance variable. I guess this just plays into the whole "not needing to program, template, reuse, repeat, instance based sprite system". I guess it's either been overlooked, or just isn't possible?

B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Tue Dec 18, 2012 12:53 am

I had another thought. I understand now that "every x seconds" is a system event, so it has to be separate from the object/instance events (or that seems to be the idea anyways)

Question:
Could we get an additional event added to object (sprite) events list?
-Every X Seconds

The idea being is the same as the system events, but for the objects instead. As well as, having it be instanced (otherwise they wouldn't be different from the system version).

I guess I've noticed that in every game I've made I've had at least one (but usually several) objects that I use in an "instanced" fashion, and giving them small randomness to their actions seems to bring a little life to the project. Not that it's hard to make a timer (now that I know how), but it'd be easier and more straight forward with an object based event option.

Just thinking out loud...
B
16
S
1
G
3
Posts: 43
Reputation: 2,597


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], BinaryPanda, MarkThomas and 19 guests