How do I destroy enemy bullets from specific enemy instance

0 favourites
  • 3 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • 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 ... zBxVzZuOHc

    What am I doing wrong ?

    If anyone can please help, that would be great! Thanks a lot!

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

  • Try Construct 3

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

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