How do I create a unit that shoots 1 projectile?

0 favourites
  • 7 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hi everyone,

    I looked around hours and days but I don't know if I do wrong or if Construct 2 has a bug.

    I have several units of the same instance that spawn and need to shoot one projectile once an enemy reaches their range.

    When they do so, some units (not all) will shoot more than 1 projectile.

    This is really annoying because it breaks all balancing tweaks.

    Do you have any idea of what I am doing wrong?

    Here is a short Capx I made to focus on my issue.

    Thank you for your help. I don't know how to fix this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Removed all the "For each"'s and the problem disapeared. "For each" isnt necesary for what you are doing.

  • Duh!

    Thank you lmchucho

    it works well indeed without "For each"

    I will become crazy, I don't know why when I tried at home without the event "For each" it only works for one unit.

    Now, it is working perfectly without it

    Thank you for your time

    Cheers

  • lmchucho

    Actually, it does not work for my mechanic.

    I need to keep "For Each" because I can have bigger enemies that overlap other enemies. Therefore, I use a variable that correspond to their Y position.

    Like that, my characters can shoot the correct enemy because they are on the same Y.

    I tried to remove for each and now, my characters shoot but their projectile pass through the enemy. Which is normal because they do not match their Y position anymore.

    If I remove the variable for the Y position, the projectile will hit the enemy that is not on the same line but can overlap the Y position.

    Anyway, I really believe that there is a bug because it does not make sense why "For Each" will impact the Spawning Event even if I put a Trigger Once.

  • Underdog

    I am not a computer where I can look at your CAPX but let me give this a shot.

    Add an instance variable to your enemy called Bullets - make that 1.

    Add an event- on enemy spawn bullet - subtract from enemy instance variable 1.

    Another Event - enemy spawn bullet if instance variable is equal to or greater than 1.

    (PLUS whatever other actions you have to spawn bullets such as in line of sight or whatever)

    See if that works. Again I am doing this without looking at your CAPX so I have no idea if that is relevant.

  • Hey Robertjs3,

    nice idea Robertjs3

    In the capx, I did not use this approach.

    I used a boolean for the same purpose but on my main capx and it did not work neither.

    However, I will investigate because I may use it at the wrong place. Thank you, I will double check my events, you may point something I do wrong

    I'll keep you posted guys,

  • robertjs3

    It works with a variable that I set to 0 before it spawns the projectile and once the animation is finished, I set it back to 1.

    Thanks again guys!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)