Make multiple enemies behave on their own?

Get help using Construct 2

Post » Wed May 30, 2012 10:56 pm

Hello everyone,

I started with Construct a few days ago and so far have been having a great time. However I seem to be stuck on making multiple instances of the same enemy not mime each other.

I've set up an event sheet for the enemy and made some event groups for things like attacking, being idle and getting hit by the players attacks. These work great with only one enemy, but if I drop in some more they all move exactly the same and will all attack even if the player is in range of only one.

If somebody can point me in the right direction it would be greatly appreciated.

Thanks.

capx
(WASD to move, click to attack)
B
8
S
1
G
1
Posts: 5
Reputation: 1,037

Post » Wed May 30, 2012 11:14 pm

Welcome!

I looked at your capx, and I'm thinking that instead of testing for distance using the distance function, you might pin an invisible sprite to each glob to simulate each one's range of sight. You can make it as big or small as you want.

Whenever the player collides with it, the individual glob it's attached to will react by attacking or fleeing or whatever.
joeykid62012-05-30 23:16:08
B
12
S
5
G
5
Posts: 26
Reputation: 4,001

Post » Thu May 31, 2012 12:05 am

I didn't look at your capx, but using groups for multi-instances programming isn't a good idea as groups are globally activated or deactivated. So if one of your instances triggers the activation of a group, the code within this group will be executed no matter what.

You should use instances variables and check them in a top event for each of your states.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu May 31, 2012 12:13 am

Here's a quick example of how to get individual enemies to respond using an invisible sprite for range of sight. I've kept the sprites visible in the example so you can see what's going on:

http://dl.dropbox.com/u/47015043/construct2/range-of-sight-example.capx
B
12
S
5
G
5
Posts: 26
Reputation: 4,001

Post » Thu May 31, 2012 12:17 am

Thanks for the help guys. I think I've got it figured out, now I just need to get to work!
B
8
S
1
G
1
Posts: 5
Reputation: 1,037

Post » Thu Mar 07, 2013 8:47 pm

Holy joeykid6!! this capx helped me a lot!!!!!! thank you mate =) Exactly the example i was looking for!
B
9
Posts: 4
Reputation: 615

Post » Thu Mar 07, 2013 9:32 pm

We also have the new turret behavior now that can also be used to check targets within range.

Edit: went ahead and made Joeykid6's example work with turret movement.

https://dl.dropbox.com/u/85412219/forumposts/TurretForRange.capx

This automates rotation speed, and give you other options like predictive aim, where the bad guys can anticipate your direction.
Paradox2013-03-07 21:57:48
B
201
S
52
G
30
Posts: 897
Reputation: 36,621


Return to How do I....?

Who is online

Users browsing this forum: emoticon, makkancs and 22 guests