How do I Spawn Bullet On Each Instance Thats True

0 favourites
  • 5 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • Spawning multiple soliders of the same object type (Soldier1)

    When Soldier1 has line of sight it sets HasLineOfSight to True

    When a Soldier1 Intances turns LineOfSight to True it should spawn a bullet and set angle towards the Enemy

    Here is what I have

    Pick Solider1 where HasLineOfSight (true)

    (sub) - Enemy - Pick nearest to (Soldier1.X, Soldier1.Y)

    System - Every 2 Seconds

    System - For Each Soldier 1

    Action: System - Create Object bullet on layer 1 at (Solider1.X, Soldier1.Y)

    Bullet - Set Angle toward (Enemy.X, Enemy.Y)

    Bullet - set bullet(behaviour) enabled

    What Happens

    Now what happens with the above is that each Soldier1 that HasLineOfSight (true) will spawn a bullet, but instead of setting angle towards the closest Enemy, they all set the Bullet angle towards only one of the Enemies, and I am not sure which instance the bullet is choosing.

    I need each solider to spawn a bullet and set its angle toward the enemy that is closest to him.

    Sometimes what will happen is that only one of the instances will spawn a bullet, but that only happens when I mess around with it.

    Please Help Me Fix This

    Please help me figure out how to get each solider to spawn their own bullet and set the bullets angle toward the enemy that is closest to him.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Plenty of different ways to do this


    It might be simpler to use the Turret Behavior....Its already set up to perform exactly what you want

    But just make the actual Turret object invisible so it doesnt look silly

    Pay attention to the following Event

    'On shoot'

    Triggered at the frequency given by the Rate of fire property, when the turret both has a target and has rotated to point towards it. If the turret is to fire upon the target, you should spawn a projectile from the turret in this trigger.

    You can make the turret do anything..such as spawn the bullet at a certain location etc

  • I'll give it a shot and post the resukts.

  • Yep you'll probably find it much easier to use once you understand how it can handle hundreds of Enemies on the screen at once and will target them based on nearest distance or by first sighted

    its pretty neat and will save you so much time once you set it up

  • Success so far. Thank you for the tip. This actually works quite well and will be quite a bit less code than the other way I was thinking about doing it which now that I think about it was sort of just creating the turret manually when all was said and done.

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