How do I destroy enemy bullets from specific enemy instance

Get help using Construct 2

Post » Fri Jul 22, 2016 5:31 am


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 ... zBxVzZuOHc

What am I doing wrong ?
If anyone can please help, that would be great! Thanks a lot!
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.
Posts: 1,581
Reputation: 60,458

Post » Fri Jul 22, 2016 6:32 am

I just tried that, works perfectly!!

Thank you so much!!
Posts: 14
Reputation: 528

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, David181, dop2000, fens and 13 guests