How do I Spawn Bullet On Each Instance Thats True

Get help using Construct 2

Post » Tue Aug 02, 2016 10:13 pm

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.

Image
B
9
S
3
Posts: 50
Reputation: 804

Post » Wed Aug 03, 2016 1:43 am

Plenty of different ways to do this
but
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

https://www.scirra.com/manual/152/turret

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
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Wed Aug 03, 2016 1:52 am

I'll give it a shot and post the resukts.
B
9
S
3
Posts: 50
Reputation: 804

Post » Wed Aug 03, 2016 2:54 am

Yep you'll probably find it much easier to use once you understand how it works....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
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Wed Aug 03, 2016 4:24 am

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.

Image
B
9
S
3
Posts: 50
Reputation: 804


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests