How do I handle multiple enemy instances correctly?

Get help using Construct 2

Post » Thu Sep 08, 2016 10:13 pm

Hello there.

Im having some trouble to figure out how to handle multiple enemy instances in Construct:

1. I'd like to create a enemy (Meele) type that walks into a direction, stops upon collision with the player, then proceeds to spawn and destroy a hitbox (Blade) in regular intervals until the player moves away.

Image

http://imgur.com/a/zNL0i

I tried to do somethings like that here, but obviously im missing something important, because all it does is spawn the hitbox and then nothing.

2. Is there a better way to do these kinds of actions?

3. Can you recommend some good resources for learning how to handle multiple instances of an object?

Thank you very much in advance!
B
3
Posts: 4
Reputation: 183

Post » Thu Sep 08, 2016 11:18 pm

It's because the state ramains with value 1 and you have "trigger once" enabled, which means that this condition will be triggered only once until it's true every next frame.

Just change the state value to 2 or whatever different than 1 just after destroying the blade.
ImageImageImage
B
27
S
16
G
73
Posts: 975
Reputation: 41,169

Post » Fri Sep 09, 2016 12:55 am

Check this example out, maroclips. :mrgreen:

https://www.dropbox.com/s/63920ksdpf9tl ... .capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 09, 2016 7:49 am

Hello again. Thanks a lot for the answers!

I was trying to get to a solution for this problem actually. I made a short gif to explain what I mean here:

Image
http://imgur.com/a/jVAbs

So these enemies shoot as soon as they see my player character in front of them. On frame 5 i spawn a bullet at a certain image point.

When I step into the Line of Sight of a single enemy or two enemies shoot at different times, it works just fine.

The problem arises as soon as I step into the line of sight of multiple enemies at the same time. As you see in the gif, what happens is that one of the Enemys spawns multiple bullets at the same time for some reason

Image
B
3
Posts: 4
Reputation: 183

Post » Fri Sep 09, 2016 11:02 am

I think this happens because when I check if frame "5" is currently playing, he checks every single instance of the animation.

Problem is I really dont know how to bypass that.

Edit: Seems like this is what Im getting wrong r154-for-each-and-trigger-once_t92702 , still cant figure out how to make it work tho
B
3
Posts: 4
Reputation: 183

Post » Fri Sep 09, 2016 11:26 am

So I've been toying around with it a bit and it kinda works now.

Turns out using system conditions kinda fucks up everything when you're trying to handle multiple instances.

Image

this is how it looks now.
B
3
Posts: 4
Reputation: 183

Post » Fri Sep 09, 2016 1:13 pm

The game looks great. :mrgreen:

We usually use Families for handling multiple instances of enemies, but it's very important to know how to pick the correct instance when we use them.

Along with functions and arrays, system conditions will definitely reduce time for developing games, but they're difficult to learn.

I'm not much of a fan for those features myself, so I don't know much about them.

But after making so many lines of codes manually using variables, sometimes I feel it would be better for me to learn the features the experts use.

Here's an example that explains the process of using Families for multiple instances.

https://www.scirra.com/tutorials/4843/p ... m-a-family

Look for functions and arrays under Tutorials category, and also visit this page to find frequently asked questions for all topics. :mrgreen:

viewtopic.php?t=63692&start=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 09, 2016 2:00 pm

Dont understand why you dont use the turret behavior.

Give it a range, target the player. Give it intervals.
'on target aquired' start the shooting animation
Then 'on shoot' spawn the bullets.
Done.

Or.
'on target aquired' start the shooting animation
'on animation end' spawn the bullet and restart the animation

You need the lineofsight only if there are obstacles in play.
In that case.

'on shoot'
'has lineofsight'
spawn the bullets

or

Or.
'on target aquired'
'has lineofsight'
start the shooting animation


'on animation end' spawn the bullet and restart the animation
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: unxcellent and 4 guests