How do I activate enemies by distance??

Get help using Construct 2

Post » Thu Sep 04, 2014 10:17 am

hi guys i have this problem with my enemy AI... see i have it that if the enemy is on screen it will attack...
but i dont want this.... i want my enemies to attack when the are at certain distance...so some can attack off-screen

but i have tried

for each enemy
>compare: distance( player.x,player.y,enemy.x,enemy.y) < than 2500 pixels
>>then attack

but this does not seems to work...since the picking is incorrect..
can you awesome gurus of wisdom give me a hint??
thanks in advance!! n.n
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Thu Sep 04, 2014 10:40 am

Give the enemy the Line Of Sight behaviour, then set their Range attribute. You can then make an Event to trigger when the enemy has Line of Sight, which automatically checks the range input.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Thu Sep 04, 2014 10:43 am

@inquiesco
mmm why i didn't think of that?? that works... but isnt LOS heavy on the cpu??
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Thu Sep 04, 2014 10:45 am

Not sure on that as I'm just diving into Construct 2 in earnest myself and am currently not sure of how to monitor CPU usage while debugging, but I've been using LOS for a few enemy AI at the moment because it's the only way I could check distance and object facing.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Thu Sep 04, 2014 10:51 am

Can you post screenshot of your event at least? [Condition: Pick By Comparison] Comparing distance should work but I think you dissociated it somehow.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Thu Sep 04, 2014 11:32 am

@DuckfaceNinja

picking by comparison gives me the same result...

here is the screen shot:

https://www.dropbox.com/s/tehtszmw7yhm8 ... o.png?dl=0
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Thu Sep 04, 2014 12:39 pm

Lunatrap wrote:@DuckfaceNinja

picking by comparison gives me the same result...

here is the screen shot:

https://www.dropbox.com/s/tehtszmw7yhm8 ... o.png?dl=0

Oh, I see what you mean by "for each" in your first post, totally forgot about that. Allright, I can't really see what's wrong there but the picking and the "for each" seems to be redundant. I'm not too sure but I want to suggest to remove "for each" block, and make the picking block as parent, to see what's going happen.

If that doesn't help, the "anglemirror" is the most probable culprit that I can see.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Thu Sep 04, 2014 12:49 pm

@DuckfaceNinja

removing the "for each" did the job...i will continue testing n.n if something goes wrong i will report
thanks a lot n.n
B
23
S
6
G
3
Posts: 316
Reputation: 3,461


Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 2 guests