How do I destroy enemy bullets from specific enemy instance

Get help using Construct 2

Post » Fri Jul 22, 2016 5:31 am

Hi,

I cannot figure this out, it's driving me crazy :)

I have 3 sprites : Player (green), EnemyShip (blue) and EnemyBullet (red).
Player can also shoots bullets (different sprite called PlayerWeapon) that can destroy EnemyShip.

My code is like this :

Event 1 :
Every 5 seconds / Trigger once -> Create object EnemyShip on Layer 0 (at random Y position)

Event 2 :
Every 1 second -> ------ EnemyShip spawn EnemyBullet
---------------------------------EnemyBullet set angle toward (Player.X, Player.Y)

Event 3 :
PlayerWeapon on collision with EnemyShip -> ---------- EnemyShip Destroy
----------------------------------------------------------------------------- PlayerWeapon Destroy
----------------------------------------------------------------------------- EnemyBullet Destroy

My problem is that ALL the EnemyBullets on the screen are destroyed once I hit any of the Enemy ships. I would like it so that ONLY the bullets (and the enemy ship that's hit) from the ship that spawned them, are destroyed.
So, if the third enemy in this picture (circled in yellow in the below picture), gets hit by my weapon, I would like it so that both that enemy and ONLY its bullets are destroyed. Not all the bullets on the screen.

Picture
https://drive.google.com/open?id=0B2knB ... zBxVzZuOHc

What am I doing wrong ?
If anyone can please help, that would be great! Thanks a lot!
B
6
S
2
Posts: 14
Reputation: 528

Post » Fri Jul 22, 2016 6:07 am

Add an instance variable to your EnemyBullet called "source". When you spawn your bullet, set EnemyBullet.source to EnemyShip.UID. Now every bullet has an identifier for which ship it came from.

When destroying the enemy ship, add a sub event to pick all EnemyBullet by UID - EnemyShip.UID, then destroy EnemyBullet. Only the picked bullets well get destroyed.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446

Post » Fri Jul 22, 2016 6:32 am

I just tried that, works perfectly!!

Thank you so much!!
B
6
S
2
Posts: 14
Reputation: 528


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 8 guests