How do I make multiples of the same enemy?

Get help using Construct 2

Post » Mon Jul 11, 2016 10:56 am

Hi, I feel like a real dummy right now, I'm having trouble figuring out why my code isn't working and I could use some help.

Image

Here is all of the movement code for this enemy. When they have line of sight with the player, their state changes to 3 if the player's on their left and 4 if the player's on their right. If they don't have line of sight, they randomly choose a behavior between 0 and 2 every couple seconds. This works perfectly! ...For the first enemy I plop down. Any more enemies I put down do not follow this behavior and don't move at all until the player enters their LOS. They also do not lose sight of the player upon leaving their LOS.

What am I doing wrong here? Again, the first enemy I plop down on the layout works exactly as I'd like it to including losing the player upon exiting its LOS.

edit: Also, when one is alerted, the awareness marker appears over all of their heads instead of just the alerted one.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Mon Jul 11, 2016 2:39 pm

Hey, I can't identify an obvious problem from your events and it's a bit odd your first enemy works while the rest don't. I'm wondering if it is something to do with how your events are structured which is throwing the whole thing off.

Could you post up/PM me your capx and I'll have a play around with it?
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Mon Jul 11, 2016 3:29 pm

I can't see any issue either from your screenshot... using a "for each" loop should pick each instance that meets the conditions you have specified.

A capx would be beneficial so we can play around with it and see what can be done.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Mon Jul 11, 2016 6:24 pm

I managed to fix the problem by removing everything from the 'for each' event. I've got no worldly idea why that worked, because I thought it had to be inside the 'for each' to work on an individual basis, but it did! If either of you would like to take a look at my capx and help me figure out why (which I'd definitely appreciate), here it is:

https://www.dropbox.com/s/jpn6loz49rm41 ... .capx?dl=0

Use the arrow keys to move. Skeletons should aggro on you individually when you come within their LOS range variable.

edit: I should also note for posterity that the sprites aren't mine, they're from Castlevania, they're just there as placeholders until I bring in an artist to help me (I have no artistic talent whatsoever).
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Jul 12, 2016 9:29 am

So I've had a play around with your Capx and as far as I can tell you don't need to remove all the var_state events from the for each enemy loop. The issue you described only seems to arise when you put the LOS condition inside the loop. When that condition is outside the loop, it all (seems) to work pretty well! Is that correct?

I can only guess that this is caused by the system looping through the enemies quickly, which causes an problems with the calling of the every 2 second condition.
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Tue Jul 12, 2016 11:04 am

You're right, removing the line of sight stuff from the 'for each' event fixed everything. Weird! Thank you for the help.

I am having another logic flaw issue that I can't untangle that maybe you could help me with as well. I have a state for the enemy attacking that creates a hitbox every time a countdown variable reaches 0 (along with setting the enemy to the attack animation):

Image

It subtracts 1*dt from the countdown whenever the enemy's state is 6, and at 0 the attack happens and it resets to 1. In theory, this should work for each skeleton individually since it's under the 'for each' event.

But it doesn't. When more than one skeleton is in range at once, it creates dozens of hitboxes at once even though I have those 'trigger once' actions set. At 3 skeletons it stops subtracting from both their countdowns. As more skeletons come in range it gets even more broken. What am I doing wrong now?

Image

https://www.dropbox.com/s/jpn6loz49rm41 ... .capx?dl=0

Here is the updated capx file for you to fiddle with.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Jul 12, 2016 12:06 pm

Ok so I did a quick restructure and got what you want working :). It was weirdness from the for each enemy loop and your subtract 1*dt. I removed the var6 code in the screenshot from the for each enemy loop and changed a couple of things.

http://imgur.com/I9WklhU

Ok I've added a link because the screenshot was crazy out of the box for some reason.

This works how you want it, while the player is stood still. If you run through groups of enemies you will still see high hitbox values, because you are swapping var states as the player moves past and therefore removing the attack cool down associated with var6. I'd recommend adding another var (attack cool down) which is independent of the enemy state vars.

Let me know if I can help anymore :).
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Tue Jul 12, 2016 3:13 pm

Ahh, thank you! That's also very odd, I don't quite get why the 1*dt was making things go screwy. The only trouble now is that when multiple skeletons are in range, they all attack at the same time, which I was trying to keep from happening (unsuccessfully, as we've seen :lol: ). It subtracts from var_attackcountdown at the same time for every skeleton, instead of subtracting on an individual basis. Any ideas?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Jul 12, 2016 5:20 pm

You could increase your var_attackcountdown by one, which should introduce some variation in the pace at which your enemies attack. I just had a go and got two groups attacking at different times. If you want to keep the 1s attack time you could subtract 0.5 every second. That help? :)
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Tue Jul 12, 2016 5:40 pm

That works! Thank you for all the help. :)

I'm still a bit mystified as to why your fixes worked so if anybody can shed some light on that feel free, but other than that, I have no more issues at the moment.
B
18
S
9
Posts: 103
Reputation: 1,817

Next

Return to How do I....?

Who is online

Users browsing this forum: AllanR, brunopalermo, farsen, ST314 and 27 guests