How do I shoot only 1 bullet per enemy?

Get help using Construct 2

Post » Mon Apr 07, 2014 2:35 pm

+Enemy: animation "Attack" is playing
+Enemy: frame = 2
+ForEach Enemy
+Trigger Once
-> Spawn bullet

Only 1 instance of enemy is shooting one bullet per Attack Animation 2nd frame. The other enemy instances are all shooting 8-10 bullets each time they go into "Attack" anim 2nd frame.

I already tried putting "Trigger once" before the foreach. It doesn't work still.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 07, 2014 3:12 pm

What seens to be happening is that when any Enemy is in the 2nd frame of the animation, you tell all the enemies to spawn a bullet. Try removing the for each, only the specific enemy which is on frame 2 should spawn the bullet.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Mon Apr 07, 2014 3:30 pm

hmm, I thought the ForEach condition was meant to make the specified object's multiple instances to act independently from other. I thought my code meant that even if there is a situation wherein all instances are in Attack anim 2nd frame, they would still fire just 1 bullet each.

Anyway, I tried disabling the Foreach (but still with trigger once), each enemy only shoots 1 bullet. I'm not sure if this really fixes the problem, but the hitbox (spawned by each bullet and pinned to the bullet that spawned it) is only pinning for 1 enemy's bullets. I think this might be related to the original problem. Still trying different stuffs at the moment.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 07, 2014 6:27 pm

Could you upload a capx? makes it easier to see whats happening. Also tell exactly what you are trying to achieve and me or someone else might be able to help you.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Mon Apr 07, 2014 10:23 pm

I put one bullet enemy for each enemy, create instance id in both.
numerate with
for each bullet order by iid ===> bullet.id=bullet.iid
for each enemy order by iid ===> enemy.id=enemy.iid

and say:
when bullet.id = enemy.id ===> shoot

wen the bullet is out of te label or out your owner limits, you can stop it, and put in pos(-1000,-1000) for example.

if need to have the same nbr of enemies and the bullets.

I made a game in this way a work perfectly.


Best regards
Paberb
B
6
S
1
Posts: 47
Reputation: 518

Post » Sun Apr 05, 2015 8:40 am

Have you solved the problem, I have the same trouble.
B
20
S
4
Posts: 51
Reputation: 1,104

Post » Mon Apr 06, 2015 2:01 pm

@bangoo

I changed the order of trigger once (see below) and it has worked ever since. I don't know why it wasn't working like this back then.

+Enemy: animation "Attack" is playing
+Enemy: frame = 2
+Trigger Once
+ForEach Enemy
-> Spawn bullet

Also, another alternative for trigger once is to use "On frame changed" (which is a trigger condition), but it doesn't work if the animation frame is 0 (1st frame, zero-based) so if your frame is 1 or higher, use "on frame changed". It will surely spawn just 1 bullet

edit:

wow this brings back memories of this problem. this was one year ago :lol:
B
16
S
7
Posts: 301
Reputation: 2,726


Return to How do I....?

Who is online

Users browsing this forum: jasontoups, raptor0555 and 1 guest