0 Favourites

How do I destroy enemy bullets from specific enemy instance

  • Hi,

    I cannot figure this out, it's driving me crazy <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    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!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • I just tried that, works perfectly!!

    Thank you so much!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,152
karshinkoff's avatar
karshinkoff
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,373
rexrainbow's avatar
rexrainbow
Unread hot topic
56 4,735
MPPlantOfficial's avatar
MPPlantOfficial