How do I make separate enemies behave independently?

Get help using Construct 2

Post » Tue Apr 29, 2014 2:33 am

Hi everyone,

I have made an "enemy" in my game. It has various events that work fine while I only have 1 in the layout. But when I add another they seems to share some behaviors. For example, if you one has line of sight, so does the other and events that are triggered effect both, instead of just the one with LOS. I noticed "Families" in the project area, and was wondering if i have to use that, or if there is another way to make the "enemies" at in dependently. After looking in the manual "families" seem to be the easy way to do this. If you need more info just let me know.

Thanks,
B
6
Posts: 11
Reputation: 272

Post » Tue Apr 29, 2014 2:52 am

I am not sure if families are available on the free version of Construct 2.

Anyhow, I guess you are using instances of the same object and that is why they behave the same. You can either:

1) Create a separate entity (clone object type) so that they'll be totally independent from each-other
2) Create an Instance Variable (perhaps a text so to give your enemies names) and in the event sheet create conditions that check (compare) the Instance Variable (name) and add actions accordingly for each enemy.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Tue Apr 29, 2014 3:10 am

Thanks eli0s,

Families are a paid feature. I am considering buying the personal version, especially if it saves me work :D .

I read the docs on instances and instance variables and thought that each instance tracked its own variables. Maybe I misunderstood.

I've been using a path finding a line of sight tutorial to get some of my events working. I noticed they have a For each loop for the enemies. I tried to use that but couldn't figure it out initially. Think that could help?

I'm trying to avoid making events for each instance. If thats one of the limitations of the free version, I'll probably get the personal license.
B
6
Posts: 11
Reputation: 272

Post » Tue Apr 29, 2014 4:10 am

C2 picks all instances unless you choose otherwise. Probably faster to post what you have so someone can have a look. Families won't help in this case.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Apr 29, 2014 4:42 am

Use System: For Each (object name)

and also use the instance variables' values as conditions.

Somewhere in your events, you have to randomize OR use another way to put different values in each instance variable of each object instance, because otherwise, using "for each" would be pointless.

families is for grouping different objects together.

Family "ENEMY" would include: Soldier object, Boxer object, Swordsman object, etc.

Based on your description, For Each is what you need, not families. Read more about For Each in the manual.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Apr 29, 2014 1:17 pm

Thanks for the feedback. I haven't had time to dive into the "For each" but I'll give that a try. Here is my (very simple) game at the moment. The "enemies" are supposed to act kinda like zombies, but I don't want them to act together (at least not right now).
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 11
Reputation: 272

Post » Tue Apr 29, 2014 7:49 pm

Hmmm... It's more complicated than I expected. I like what you already have set up. I can't figure out how to make the instances behave separately with an Instance Variable and the "For Each" loop gives me an error at run time.
The only thing I am confident that it will work is to use different objects for each enemy, but this isn't very practical if you have a lot of enemies. Actually, it's rather dumb...

Perhaps an advanced forum member can help here..?

I am sorry for not being able to help :(
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Wed May 07, 2014 11:29 pm

Thanks for all the responses. I was able to get the "For each" loop to work ( or at least do what I needed). I have found other things that I need help on now, so I'll make a new post. Here's what I game file incse anyone else is doing something similar and can use it. Just FYI there aren't comments, and there are some disabled chunks. But feel free to PM me if you need help deciphering it lol.
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 11
Reputation: 272

Post » Fri May 16, 2014 4:22 am

Here is a small update. I removed the "For Each" to get some other stuff to work. I wanted the enemy to stand still and "attack"(once I make animations). So now they will stop and rotate towards the player when overlapping him. I found that sometimes they would run through the player and then lose sight of him. Since my enemies are supposed to be like zombies, I felt that they wouldn't just run by fresh meat because they missed :D.
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 11
Reputation: 272


Return to How do I....?

Who is online

Users browsing this forum: Rhindon, YoHoho and 23 guests